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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ChristianDGreat
Resolver I
Resolver I

Create a Calendar Table based on a Table (From and To)

So we have a table like this in our Database

 

Date StartDate EndProductSeason
1/21/20221/22/2023A2023
6/2/20226/4/2023B2023
10/2/202210/3/2023C2023
1/22/20211/20/2022

A

 

2022
6/3/20216/1/2022B2022
10/5/202110/1/2022C2022

 

You can see on Row 1, that on Product A, its own calendar start at 1/21/22 and ends on 1/22/2023 and so forth.

I want to build something like this

DateProductSeason
1/21/2022A2023
.A2023
.A2023
.A2023
.A2023
1/22/2023A2023
6/2/2022B2023
.B2023
.B2023
.B2023
.B2023
6/4/2023B2023

 

The . . . means the date  between the from and to. (if it makes sense). (so on row 2 the date will be 1/22, then row 3 will be 1/23 and so on and so forth)


Is this possible?

 

Thanks

Chris

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY5JDsAgCAD/4tmErfVefQbx/98QW1CbYDKHkUE1EbANMqc8mSeL8WPvxZ41FeBwClyh1FMh3I6xhNR+kgfoi2F88Bh7TMIpsG6rp2KBe+3BLbUl9QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date Start" = _t, #"Date End" = _t, Product = _t, Season = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Start", type date}, {"Date End", type date}, {"Product", type text}, {"Season", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Dates([Date Start], Duration.TotalDays([Date End]-[Date Start])+1, #duration(1,0,0,0))),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Product", "Season", "Custom"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Other Columns", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom", "Date"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}})
in
    #"Changed Type1"

 

Pat

Microsoft Employee

View solution in original post

2 REPLIES 2
ppm1
Solution Sage
Solution Sage

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY5JDsAgCAD/4tmErfVefQbx/98QW1CbYDKHkUE1EbANMqc8mSeL8WPvxZ41FeBwClyh1FMh3I6xhNR+kgfoi2F88Bh7TMIpsG6rp2KBe+3BLbUl9QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date Start" = _t, #"Date End" = _t, Product = _t, Season = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Start", type date}, {"Date End", type date}, {"Product", type text}, {"Season", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Dates([Date Start], Duration.TotalDays([Date End]-[Date Start])+1, #duration(1,0,0,0))),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Product", "Season", "Custom"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Other Columns", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom", "Date"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}})
in
    #"Changed Type1"

 

Pat

Microsoft Employee

Thanks! I was able to do that too using List in power query, thanks!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors