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! Learn more

Reply
jcastr02
Post Prodigy
Post Prodigy

range of dates when a column changes

I have list of stores, but with eff_date (effective date) and end_dt(end date).  How can I achieve to only get range of dates when the DE_Support column Changes.  See desired result table on right side.  

DATA in PQ   Desired Result  
str_nbreff_dtend_dtDE_Support Str_nbreff_dtend_dtDE_Support
238/24/2023null0.15 238/24/2023 0.15
2312/1/20228/23/20230.45 2312/1/20228/23/20230.45
2310/29/202211/30/20220.15 232/26/202111/30/20220.15
239/8/202210/28/20220.15 231/8/20212/25/20211
232/11/20229/7/20220.15 235/2/20191/7/20210.15
231/28/20222/10/20220.15 4810/4/20185/1/20190.6
2311/5/20211/27/20220.15 483/6/201710/3/20180.55
239/10/202111/4/20210.15     
239/9/20219/9/20210.15     
232/26/20219/8/20210.15     
231/8/20212/25/20211     
2312/3/20201/7/20210.15     
236/6/202012/2/20200.15     
236/4/20206/5/20200.15     
233/20/20206/3/20200.15     
2310/18/20193/19/20200.15     
239/5/201910/17/20190.15     
235/24/20199/4/20190.15     
235/2/20195/23/20190.15     
4810/4/20185/1/20190.6     
486/6/201810/3/20180.55     
485/29/20186/5/20180.55     
485/3/20185/28/20180.55     
481/4/20185/2/20180.55     
4811/24/20171/3/20180.55     
489/22/201711/23/20170.55     
489/7/20179/21/20170.55     
485/4/20179/6/20170.55     
485/4/20179/6/20170.55     
483/6/20175/3/20170.55     


                   

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Read about GroupKind.Local and its awesome power.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ndJJrsMgDADQu2RdxZiZs1S9QfV3vX+NwZiksPmrOPLzIIvn87DueBwZrAdrOP77vN/0MSeG4/XoAC1gBbZhJ9icflYGbBGGCM7Iz7VbgTwUkbxWNHLMLJDWCKdyKtgMpEahZrBVbHqVXo+twkt8V0USU3hf3UZFeY1QE+R1v8vV+dKGdVq3iRCHoT4S35GXRGyn+DV1lCK3RnQhrGtj4Qosa1Z4CKNakeTnqkJ7dpwp4LdIEqG9vCvyuQ3h8swKFUU17VDYuZPYnGFqFNoLxjwutUROh/H7WyCcN7Ibg/0CiQs2O9FCdiDsN0gLliRBFbhGAbyi+H/jNNGvoeb1BQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [str_nbr = _t, eff_dt = _t, end_dt = _t, DE_Support = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"str_nbr", Int64.Type}, {"eff_dt", type date}, {"end_dt", type date}, {"DE_Support", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"str_nbr", "DE_Support"}, {{"eff_dt", each List.Min([eff_dt]), type nullable date}, {"end_dt", each List.Max([end_dt]), type nullable date}},GroupKind.Local)
in
    #"Grouped Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

View solution in original post

4 REPLIES 4
jcastr02
Post Prodigy
Post Prodigy

@lbendlin Thanks so much for your help.  It seems it doesn't capture one of the rows because there is no end date (and that sometimes happens)  see below in yellow.

 

Screenshot 2024-03-11 103714.pngScreenshot 2024-03-11 103729.png

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

@lbendlinnvmind I was able to do a workaround.  Ty again for solution above! 

lbendlin
Super User
Super User

Read about GroupKind.Local and its awesome power.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ndJJrsMgDADQu2RdxZiZs1S9QfV3vX+NwZiksPmrOPLzIIvn87DueBwZrAdrOP77vN/0MSeG4/XoAC1gBbZhJ9icflYGbBGGCM7Iz7VbgTwUkbxWNHLMLJDWCKdyKtgMpEahZrBVbHqVXo+twkt8V0USU3hf3UZFeY1QE+R1v8vV+dKGdVq3iRCHoT4S35GXRGyn+DV1lCK3RnQhrGtj4Qosa1Z4CKNakeTnqkJ7dpwp4LdIEqG9vCvyuQ3h8swKFUU17VDYuZPYnGFqFNoLxjwutUROh/H7WyCcN7Ibg/0CiQs2O9FCdiDsN0gLliRBFbhGAbyi+H/jNNGvoeb1BQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [str_nbr = _t, eff_dt = _t, end_dt = _t, DE_Support = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"str_nbr", Int64.Type}, {"eff_dt", type date}, {"end_dt", type date}, {"DE_Support", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"str_nbr", "DE_Support"}, {{"eff_dt", each List.Min([eff_dt]), type nullable date}, {"end_dt", each List.Max([end_dt]), type nullable date}},GroupKind.Local)
in
    #"Grouped Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors