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
tangutoori
Helper III
Helper III

Difference between values in the same column between max and min dates

Dear Team,

 

can you help me to solve the below scenario.

 

 

INPUT   
ConcatenatePart numberChange DateValue
30Y0140,30Y01XY,30Y0160,30Y0ABC30Y014005-01-2310
30Y0140,30Y01XY,30Y0160,30Y0ABC30Y01XY06-01-2310
30Y0140,30Y01XY,30Y0160,30Y0ABC30Y016007-01-2310
30Y0140,30Y01XY,30Y0160,30Y0ABC30Y0ABC08-01-2320
30Y153430Y153411-01-2310
30Y153230Y153212-01-2310
30Y0989/30Y010030Y098913-01-2323
30Y0989/30Y010030Y010014-01-235
    
    
OUTPUT   
ConcatenatePart numbersDatesDelta
30Y0140,30Y01XY,30Y0160,30Y0ABC30Y0140 & 30YABC05-01-2023 & 08-01-2310
30Y153430Y153411-01-2310
30Y153230Y153212-01-2310
30Y0989/30Y010030Y0989 & 30Y010013-01-2023 & 14-01-202318

 

Regards,

narender.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @tangutoori ,

You can achieve it in Power Query Editor, please find the details in the attachment.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nY5LDoAgDAXvwpqEfgBxqV5CYrj/NSxUcWOMYdWhzMvrcRiGDOjBtrlnnVHfy7oZextCwaEjIBZEMMX+Tu9ZKI6mY+2eBtNK6UlTT2Ngr9ZFiG8l8kldq4T0esucZtduALi6ZVMVh9zL+UNXEt3fejClnA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Concatenate = _t, #"Part number" = _t, #"Change Date" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Concatenate", type text}, {"Part number", type text}, {"Change Date", type date}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Concatenate"}, {{"detail", each _, type table [Concatenate=nullable text, Part number=nullable text, Change Date=nullable text, Value=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Part numbers", each let 
min = List.Min([detail][Change Date]),
max = List.Max([detail][Change Date]),
result = 
if min=max 
then min
else Text.From(min) & " & " & Text.From(max)
in
result),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Dates", each let 
min = List.Min([detail][Change Date]),
max = List.Max([detail][Change Date]),
minpart = Table.SelectRows([detail],each [Change Date] = min)[Part number]{0},
maxpart = Table.SelectRows([detail],each [Change Date] = max)[Part number]{0},
result = 
if 
min = max
then minpart
else 
minpart & " & " & maxpart
in 
result),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Delta", each let 
min = List.Min([detail][Change Date]),
max = List.Max([detail][Change Date]),
mindvalue = Table.SelectRows([detail],each [Change Date] = min)[Value]{0},
maxdvalue = Table.SelectRows([detail],each [Change Date] = max)[Value]{0},
result = 
if 
mindvalue = maxdvalue
then mindvalue
else 
Number.Abs(maxdvalue-mindvalue)
in 
result),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"detail"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Part numbers", type text}, {"Dates", type text}, {"Delta", Int64.Type}})
in
    #"Changed Type1"

vyiruanmsft_0-1681983171492.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @tangutoori ,

You can achieve it in Power Query Editor, please find the details in the attachment.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nY5LDoAgDAXvwpqEfgBxqV5CYrj/NSxUcWOMYdWhzMvrcRiGDOjBtrlnnVHfy7oZextCwaEjIBZEMMX+Tu9ZKI6mY+2eBtNK6UlTT2Ngr9ZFiG8l8kldq4T0esucZtduALi6ZVMVh9zL+UNXEt3fejClnA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Concatenate = _t, #"Part number" = _t, #"Change Date" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Concatenate", type text}, {"Part number", type text}, {"Change Date", type date}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Concatenate"}, {{"detail", each _, type table [Concatenate=nullable text, Part number=nullable text, Change Date=nullable text, Value=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Part numbers", each let 
min = List.Min([detail][Change Date]),
max = List.Max([detail][Change Date]),
result = 
if min=max 
then min
else Text.From(min) & " & " & Text.From(max)
in
result),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Dates", each let 
min = List.Min([detail][Change Date]),
max = List.Max([detail][Change Date]),
minpart = Table.SelectRows([detail],each [Change Date] = min)[Part number]{0},
maxpart = Table.SelectRows([detail],each [Change Date] = max)[Part number]{0},
result = 
if 
min = max
then minpart
else 
minpart & " & " & maxpart
in 
result),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Delta", each let 
min = List.Min([detail][Change Date]),
max = List.Max([detail][Change Date]),
mindvalue = Table.SelectRows([detail],each [Change Date] = min)[Value]{0},
maxdvalue = Table.SelectRows([detail],each [Change Date] = max)[Value]{0},
result = 
if 
mindvalue = maxdvalue
then mindvalue
else 
Number.Abs(maxdvalue-mindvalue)
in 
result),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"detail"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Part numbers", type text}, {"Dates", type text}, {"Delta", Int64.Type}})
in
    #"Changed Type1"

vyiruanmsft_0-1681983171492.png

Best Regards

lbendlin
Super User
Super User

This is not something you should attempt to do in Power BI.

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 Solution Authors
Users online (4,593)