0
votes

I want to add more rows using the Query editor (Power query/ M Query) in only the Start Date and End Date column:

+----------+------------------+--------------+-----------+-------------+------------+
| Employee |  Booking Type    |     Jobs     | WorkLoad% | Start Date  |  End date  |
+----------+------------------+--------------+-----------+-------------+------------+
| John     | Chargeable       | CNS          |        20 | 04/02/2020  | 31/03/2020 |
| John     | Chargeable       | CNS          |        20 | 04/03/2020  | 27/04/2020 |
| Bernard  | Vacation/Holiday | SN           |       100 | 30/04/2020  | 11/05/2020 |
| Bernard  | Vacation/Holiday | Annual leave |       100 | 23/01/2020  | 24/02/2020 |
| Bernard  | Chargeable       | Tech PLC     |        50 | 29/02/2020  | 30/03/2020 |
+----------+------------------+--------------+-----------+-------------+------------+

I want to find the MIN(Start Date) and MAX(End Date) and then append the range of start to end dates to this table only in the Start Date and End Date column in the Query Editor (Power Query/ M Query). Preferrable if I can create another table2 duplicating the original table and append these rows. For example:

+----------+------------------+--------------+-----------+-------------+------------+
| Employee |  Booking Type    |     Jobs     | WorkLoad% | Start Date  |  End date  |
+----------+------------------+--------------+-----------+-------------+------------+
| John     | Chargeable       | CNS          |        20 | 04/02/2020  | 31/03/2020 |
| John     | Chargeable       | CNS          |        20 | 04/03/2020  | 27/04/2020 |
| Bernard  | Vacation/Holiday | SN           |       100 | 30/04/2020  | 11/05/2020 |
| Bernard  | Vacation/Holiday | Annual leave |       100 | 23/01/2020  | 24/02/2020 |
| Bernard  | Chargeable       | Tech PLC     |        50 | 29/02/2020  | 30/03/2020 |
|          |                  |              |           | 23/01/2020  | 23/01/2020 |
|          |                  |              |           | 24/01/2020  | 24/01/2020 |
|          |                  |              |           | 25/01/2020  | 25/01/2020 |
|          |                  |              |           | 26/01/2020  | 26/01/2020 |
|          |                  |              |           | 27/01/2020  | 27/01/2020 |
|          |                  |              |           | 28/01/2020  | 28/01/2020 |
|          |                  |              |           | 29/01/2020  | 29/01/2020 |
|          |                  |              |           | 30/01/2020  | 30/01/2020 |
|          |                  |              |           | 31/01/2020  | 31/01/2020 |
|          |                  |              |           | ...         | ...        |
|          |                  |              |           | 11/05/2020  | 11/05/2020 |
+----------+------------------+--------------+-----------+-------------+------------+
1

1 Answers

1
votes

The List.Dates function is pretty useful here.

Generate the dates in your range, duplicate that to two columns and then append.

let
    StartDate = List.Min(StartTable[Start Date]),
    EndDate = List.Max(StartTable[End Date]),
    DateList = List.Dates(StartDate, Duration.Days(EndDate - StartDate), #duration(1,0,0,0)),
    DateCols = Table.FromColumns({DateList, DateList}, {"Start Date", "End Date"}),
    AppendDates = Table.Combine({StartTable, DateCols})
in
    AppendDates