Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
matherhorn64
Frequent Visitor

Table transformation - create rows for dates between - power query

Hi guys,

 

Current situation - I have this input table:

11.PNG

 

Desired situation - 

22.PNG

 

So the idea is that power query transforms the input table:

1) gets the product from product column

2) creates the date column, where the first date is [From] and the last is [To] - and between these dates there are consecutive days

3) each unique combination of [product + price + from + to] appends to each other - oucome is the desired table.

 

Do you guys think it is possible to perform that transformation in power query?

 

 

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

It is quite easy if you convert the dates to numbers, add a column with nested lists with all numbers representing the from..to dates,

remove the From/To columns, expand the new column and adjust the data type to date.

 

let
    Source = InputTable,
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"From", Int64.Type}, {"To", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each {[From]..[To]}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"From", "To"}),
    #"Expanded Date" = Table.ExpandListColumn(#"Removed Columns", "Date"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}})
in
    #"Changed Type1"
Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
MarcelBeug
Community Champion
Community Champion

It is quite easy if you convert the dates to numbers, add a column with nested lists with all numbers representing the from..to dates,

remove the From/To columns, expand the new column and adjust the data type to date.

 

let
    Source = InputTable,
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"From", Int64.Type}, {"To", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each {[From]..[To]}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"From", "To"}),
    #"Expanded Date" = Table.ExpandListColumn(#"Removed Columns", "Date"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}})
in
    #"Changed Type1"
Specializing in Power Query Formula Language (M)

Brilliant, thanks kind sir!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.