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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kkassel
Frequent Visitor

Populating list of Dates for all locations

I'm trying to create a query that lists all the calendar days between 2 dates for all locations.  I'd like the date to start at the first of the year based off the oldest date from my list. and end at the year-end of the most recent date from the list. (i.e. earliest date is 3/8/2020 so I want my dates starting at 1/1/2020 and ending at 12/31/2021)

 

This is just a small sample of the data.  There are many locations with many different dates.

LocationDate
New York7/9/2020
New York5/11/2021
New York2/2/2021
New York3/8/2020
New York11/25/2020
Philadelphia1/5/2021
Philadelphia6/19/2020
Philadelphia9/9/2021
Philadelphia10/15/2020

 

 

I'm looking to get something like this

LocationDate
New York1/1/2020
New York1/2/2020
New York1/3/2020
New York1/4/2020
 
New York12/29/2021
New York12/30/2021
New York12/31/2021
Philadelphia1/1/2020
Philadelphia1/2/2020
 
Philadelphia12/29/2021
Philadelphia12/30/2021
Philadelphia12/31/2021

 

I thinked I'd prefer to do this in power query but any DAX solutions would do as well. Any help would be greatly appreciated.  Thanks in advance.

 

 

1 ACCEPTED SOLUTION
Jakinta
Solution Sage
Solution Sage

You can try this in blank query and adjust the steps accordingly.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kstV4jML8pW0lEy17fUNzIwMlCK1UERN9U3NARJGKJLGOkbYRU31rfAahDIGFOETEBGZk5iSmpOQUZmIkhW3xRhGpqcmb6hJU6NlhB3Y9VoaKBvCLMyFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, Date = _t]),
    Grouped = Table.Group(Source, {"Location"}, {{"Gr", each List.Transform({Number.From(Date.StartOfYear (Date.From(List.Min(_[Date]))))..Number.From( Date.EndOfYear(Date.From(List.Max(_[Date]))))}, Date.From)}}),
    #"Expanded Gr" = Table.ExpandListColumn(Grouped, "Gr"),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Gr",{{"Gr", type date}})
in
    #"Changed Type"

View solution in original post

3 REPLIES 3
Jakinta
Solution Sage
Solution Sage

You can try this in blank query and adjust the steps accordingly.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kstV4jML8pW0lEy17fUNzIwMlCK1UERN9U3NARJGKJLGOkbYRU31rfAahDIGFOETEBGZk5iSmpOQUZmIkhW3xRhGpqcmb6hJU6NlhB3Y9VoaKBvCLMyFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, Date = _t]),
    Grouped = Table.Group(Source, {"Location"}, {{"Gr", each List.Transform({Number.From(Date.StartOfYear (Date.From(List.Min(_[Date]))))..Number.From( Date.EndOfYear(Date.From(List.Max(_[Date]))))}, Date.From)}}),
    #"Expanded Gr" = Table.ExpandListColumn(Grouped, "Gr"),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Gr",{{"Gr", type date}})
in
    #"Changed Type"

I think I need to use this as well, but I'm having trouble replacing everything where I need to. Can you specify what goes where by any chance?

works great.  Thank you

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors