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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
joshua1990
Post Prodigy
Post Prodigy

Expand Dates to complete ranges

Hi all!

I have a transactional table that is displays when a case was opened and when it was closed.

Case Date Start Date Closed
AAA1 01.01.2022 01.01.2023
AA2 05.02.2022 12.03.2022
AA21 06.07.2022  

 

Now I would like to expand this table in a way that I get a row for each date betweend Date Start and Date closed.

If there is no Date Closed defined, then it should be expanded to today.

 

Example

Case Date
AA2 05.02.2022
AA2 06.02.2022
AA2 07.02.2022
AA2 ...
AA2 12.03.2022

 

How would yo do that in Power Query?

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @joshua1990 

 

You can add a custom column with below code, then expand the list column to new rows. 

let
    _startDate = [Date Start], 
    _endDate = if [Date Closed] = null then Date.From(DateTime.LocalNow()) else [Date Closed] 
in
    List.Generate(()=>[x=_startDate], each [x]<=_endDate, each [x=Date.AddDays([x],1)], each [x])

vjingzhang_0-1672905470994.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0NFTSUTIyMDLSM9SDM42BzFgdsLQRXNpIz8gMyFGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Case = _t, #"Date Start" = _t, #"Date Closed" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Case", type text}, {"Date Start", type date}, {"Date Closed", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
    _startDate = [Date Start], 
    _endDate = if [Date Closed] = null then Date.From(DateTime.LocalNow()) else [Date Closed] 
in
    List.Generate(()=>[x=_startDate], each [x]<=_endDate, each [x=Date.AddDays([x],1)], each [x])),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
    #"Expanded Custom"

 

You can also add a custom column with below code then expand it to new rows. 

List.Dates([Date Start], Duration.TotalDays((if [Date Closed] = null then Date.From(DateTime.LocalNow()) else [Date Closed]) - [Date Start]) + 1, #duration(1,0,0,0))

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

=#table({"Case","Date"},List.TransformMany(Table.ToRows(PreviousStepName),each List.Dates(_{1},Duration.Days(_{2}-_{1}),Duration.From(1)),(x,y)=>{x{0},y}))

v-jingzhang
Community Support
Community Support

Hi @joshua1990 

 

You can add a custom column with below code, then expand the list column to new rows. 

let
    _startDate = [Date Start], 
    _endDate = if [Date Closed] = null then Date.From(DateTime.LocalNow()) else [Date Closed] 
in
    List.Generate(()=>[x=_startDate], each [x]<=_endDate, each [x=Date.AddDays([x],1)], each [x])

vjingzhang_0-1672905470994.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnR0NFTSUTIyMDLSM9SDM42BzFgdsLQRXNpIz8gMyFGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Case = _t, #"Date Start" = _t, #"Date Closed" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Case", type text}, {"Date Start", type date}, {"Date Closed", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
    _startDate = [Date Start], 
    _endDate = if [Date Closed] = null then Date.From(DateTime.LocalNow()) else [Date Closed] 
in
    List.Generate(()=>[x=_startDate], each [x]<=_endDate, each [x=Date.AddDays([x],1)], each [x])),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
    #"Expanded Custom"

 

You can also add a custom column with below code then expand it to new rows. 

List.Dates([Date Start], Duration.TotalDays((if [Date Closed] = null then Date.From(DateTime.LocalNow()) else [Date Closed]) - [Date Start]) + 1, #duration(1,0,0,0))

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

ImkeF
Community Champion
Community Champion

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors