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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
vanessafvg
Super User
Super User

Power Query Date Table - pull from data range

I have this great calendar table function by Matt Masson, what would be the best way to automate the date range from the dates in the data?

 

I am assuming i would need to get the min and max of the date in the data table?  What is the best way to do this in Power Query and then pass it to this function?  

 

thanks 🙂

 

https://www.mattmasson.com/2014/02/creating-a-date-dimension-with-a-power-query-script/





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




1 ACCEPTED SOLUTION
stretcharm
Memorable Member
Memorable Member

 

You can summarise your date table

 

DateRange

let
    Source = Actual,
    #"Grouped Rows" = Table.Group(Source, {}, {{"MinDate", each List.Min([Date]), type date}, {"MaxDate", each List.Max([Date]), type date}})
in
    #"Grouped Rows"

Then Reference it

I've tweaked the top of the function as follows

let CreateDateTable = (optional Culture as nullable text) as table =>
  let
    StartDate  = DateRange[MinDate]{0},
    EndDate = DateRange[MaxDate]{0},
    DayCount = Duration.Days(Duration.From(EndDate - StartDate)),

View solution in original post

1 REPLY 1
stretcharm
Memorable Member
Memorable Member

 

You can summarise your date table

 

DateRange

let
    Source = Actual,
    #"Grouped Rows" = Table.Group(Source, {}, {{"MinDate", each List.Min([Date]), type date}, {"MaxDate", each List.Max([Date]), type date}})
in
    #"Grouped Rows"

Then Reference it

I've tweaked the top of the function as follows

let CreateDateTable = (optional Culture as nullable text) as table =>
  let
    StartDate  = DateRange[MinDate]{0},
    EndDate = DateRange[MaxDate]{0},
    DayCount = Duration.Days(Duration.From(EndDate - StartDate)),

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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