Forum Discussion
Unpivot a table with dates beetwen
Hi all!
I have a table like this :
| Start_Date | End_Date | Type_of_Car | Number |
| 20/10/2024 | 25/10/2024 | Car A | 2 |
| 08/02/2024 | 12/02/2024 | Car B | 3 |
and I want to obtain (with power query or dax) a table like this:
| Date | Type_of_Car | Number |
| 20/10/2024 | Car A | 2 |
| 21/10/2024 | Car A | 2 |
| 22/10/2024 | Car A | 2 |
| 23/10/2024 | Car A | 2 |
| 24/10/2024 | Car A | 2 |
| 25/10/2024 | Car A | 2 |
| 08/02/2024 | Car B | 3 |
| 09/02/2024 | Car B | 3 |
| 10/02/2024 | Car B | 3 |
| 11/02/2024 | Car B | 3 |
| 12/02/2024 | Car B | 3 |
any suggestions?!
Thank you all!
Hi SebaSpotti
You can refer this post:
https://amitchandak.medium.com/power-query-get-all-dates-between-the-start-and-end-date-9ad6a84cf5f2it should resolved your issue, and if it does please give this a thumbs up and accept the solution
Many Thanks
Dark
3 Replies
- darkinvader_
Resolver I
Hi SebaSpotti
You can refer this post:
https://amitchandak.medium.com/power-query-get-all-dates-between-the-start-and-end-date-9ad6a84cf5f2it should resolved your issue, and if it does please give this a thumbs up and accept the solution
Many Thanks
Dark - danextian
Super User
hi SebaSpotti
You don't really unpivot but expand the start and end dates into rows of dates within the range. The custom column below will generate a list of dates whicn can be expanded into rows.
let //generate a series of numbers from the start and end dates as a list series = {Number.From([Start_Date])..Number.From([End_Date])}, //convert the numbers back to dates todates = List.Transform(series, Date.From) in todates - Bibiano_Geraldo
Super User
Hi SebaSpotti ,
Make sure that your Start_Date and End_Date the data type was set to date in power query.
After that, you can add a new custom column using this M code:
List.Dates([Start_Date], Duration.Days([End_Date] - [Start_Date]) + 1, #duration(1,0,0,0))Expand the Date List:
- Click the small icon with arrows at the top-right of the Date_List column.
- Select Expand to New Rows. This will create a row for each date in the range.
Now your data look like this:
Rename the new column to Date.
Remove the original Start_Date and End_Date columns if they are no longer needed.
Your final result should look like this: