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
jcastr02
Post Prodigy
Post Prodigy

grouping and maximums

Id like to be able to transform within Power Query table to get desired start and end date.  One store will have multiple start and end dates.  Id like for it to give me the maximum start date if a previous record for that store has ended.  Example store 3711 since the end date was already captured in one row, I'd like for table to now only display 10/26/23 as start date and no end date.  The way I'm grouping doesn't seem to work - it's grabbing info from two different rows.

Screenshot 2023-12-21 160945.png

Current Desired Result
StoreStart DateEnd Date StoreStart DateEnd Date
371110/26/2023  371110/26/2023 
371110/10/202310/13/2023 381210/1/202310/31/2023
381210/1/202310/31/2023 505012/1/2023 
505011/1/202311/5/2023    
505012/1/2023     
1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

I think, what you need is :

 

a) First step is get the max start date for each store.

b) Second step is to join back to the original data by both Store and Max Start Date and then get the corresponding End Date.

i.e., You are not looking for max end date, what you are looking is corresponging end date to the max start date of that store.

 

Let us try this and then you can enhance it to your needs:

Add group by Store, and only add max support start date column, similar to the image.

Next you can do the self merge (join) by these two columns... expand the table and select the end date.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi7JL0pV0gHSiUUlCi6JJSCOa14KhBmrE61kbG5oCBQzNNA3MtM3MjAyBnIU0GRAkhAZEMcYwgErsTA0gooiqTA2RKgwNTA1AIkaIqkw1DfFVGCEUAC0PhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Store", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Store"}, {{"Max Support Start Date", each List.Max([Start Date]), type nullable date}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Store", "Max Support Start Date"}, #"Changed Type1", {"Store", "Start Date"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"End Date"}, {"End Date"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Grouped Rows",{{"End Date", "Max Support End Date"}})
in
    #"Renamed Columns"

 

  

input:

sevenhills_1-1703200547558.png

 

output:

sevenhills_0-1703200531245.png

 

View solution in original post

1 REPLY 1
sevenhills
Super User
Super User

I think, what you need is :

 

a) First step is get the max start date for each store.

b) Second step is to join back to the original data by both Store and Max Start Date and then get the corresponding End Date.

i.e., You are not looking for max end date, what you are looking is corresponging end date to the max start date of that store.

 

Let us try this and then you can enhance it to your needs:

Add group by Store, and only add max support start date column, similar to the image.

Next you can do the self merge (join) by these two columns... expand the table and select the end date.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi7JL0pV0gHSiUUlCi6JJSCOa14KhBmrE61kbG5oCBQzNNA3MtM3MjAyBnIU0GRAkhAZEMcYwgErsTA0gooiqTA2RKgwNTA1AIkaIqkw1DfFVGCEUAC0PhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Store", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Store"}, {{"Max Support Start Date", each List.Max([Start Date]), type nullable date}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Store", "Max Support Start Date"}, #"Changed Type1", {"Store", "Start Date"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"End Date"}, {"End Date"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Grouped Rows",{{"End Date", "Max Support End Date"}})
in
    #"Renamed Columns"

 

  

input:

sevenhills_1-1703200547558.png

 

output:

sevenhills_0-1703200531245.png

 

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