I need to create a dimension table from the current "Data Set" in order to be used in Excel and Power Bi. As for the moment the information has been saved in an excel workbook.
I've simplified a workbook to set it up as an example.
Here's the Link to Download it: https://1drv.ms/x/s!AkyEWh5MlySFoWOFMTC3GDXY09eS
Currently, everything has been structured as a Pivot Table, where the column headers are dates, like so:
+----+----------+----------+----------+
| ID | 12/29/14 | 01/05/15 | 01/12/15 |
+----+----------+----------+----------+
| 00 | Darell | Darell | Darell |
| 01 | Jarrod | Annelle | Todd |
| 04 | Lakeesha | Linn | Linn |
+----+----------+----------+----------+
I've un-pivot the table and grouping the ID and name field plus calculating the minimum and maximum date value. Works like charm.
Problem comes with the last date, since this will provide me the max value for the local grouping, and in reality the last day would be one day before the next column on the original data, like so:
Here is an example:
+----+----------+----------+----------+
| ID | Name | From | To |
+----+----------+----------+----------+
| 00 | Darell | 12/29/14 | 01/05/15 |
| 00 | Kamala | 01/12/15 | ... |
| 01 | Jarrod | 12/29/14 | 12/29/14 |
| 01 | Annelle | 01/05/15 | 01/05/15 |
| 01 | Todd | 01/12/15 | .... |
| 04 | Lakeesha | 12/29/14 | 12/29/14 |
| 04 | Linn | 01/05/15 | .... |
| .. | ........ | .... | .... |
+----+----------+----------+----------+
This is a simplified code that I've created to this:
let
Source = Excel.CurrentWorkbook(){[Name="RawData"]}[Content],
#"Unpivot [Table]" = Table.UnpivotOtherColumns(Source, {"ID"}, "Date", "Name"),
#"Group [Table]" = Table.Group(#"Unpivot [Table]", {"ID", "Name"}, {{"From", each List.Min([Date]), type date}, {"On", each List.Max([Date]), type date}}, GroupKind.Local)
in
#"Group [Table]"
Here is what I'm expecting to get as a result, each name grouped locally with a start and end date.
+----+----------+----------+----------+
| ID | Name | From | To |
+----+----------+----------+----------+
| 00 | Darell | 12/29/14 | 01/11/15 |
| 00 | Kamala | 01/12/15 | .... |
| 01 | Jarrod | 12/29/14 | 01/04/15 |
| 01 | Annelle | 01/05/15 | 01/11/15 |
| 01 | Todd | 01/12/15 | .... |
| 04 | Lakeesha | 12/29/14 | 01/04/15 |
| 04 | Linn | 01/05/15 | .... |
| .. | ........ | .... | .... |
+----+----------+----------+----------+
with this I will generate each date in between "From" and "To" with
Table.AddColumn(#"Calculate [To]", "Date", each { Number.From([From])..Number.From([To]) })