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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
FieldsG
New Member

IDENTIFY THE MOMENT OF VALUE CHANGE

From the series of columns identify the first time I change the value, resulting in the header name of that column.
And in another column identify the last value before the change, also with the name of the header of that column.

But with a power query formula, not in DAX

FieldsG_0-1706902148080.png

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @FieldsG,

Result:

dufoq3_0-1706909297867.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwNzQwNDAwMjAyMjMAAiUdJUsqYUND3ERsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Long OP" = _t, #"2022-01" = _t, #"2022-02" = _t, #"2022-03" = _t, #"2022-04" = _t, #"2022-05" = _t, #"2022-06" = _t, #"2022-07" = _t, #"2022-08" = _t, #"2022-09" = _t, #"2022-10" = _t, #"2022-11" = _t, #"2022-12" = _t, #"2023-01" = _t, #"2023-02" = _t, #"2023-03" = _t, #"2023-04" = _t, #"2023-05" = _t, #"2023-06" = _t, #"2023-07" = _t, #"2023-08" = _t, #"2023-09" = _t, #"2023-10" = _t, #"2023-11" = _t, #"2023-12" = _t]),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(Source, {"Long OP"}, "Year Month", "Value"),
    AddedIndex = Table.AddIndexColumn(UnpivotedOtherColumns, "Index", 0, 1, Int64.Type),
    Ad_MomentOfChange = Table.AddColumn(AddedIndex, "Moment of Change", each try if [Value] = AddedIndex{[Index]-1}[Value] then null else [Year Month] otherwise null, type text),
    #"Added Custom" = Table.AddColumn(Ad_MomentOfChange, "Last Value Before Change", each if [Moment of Change] = null then null else Ad_MomentOfChange{[Index]-1}[Value], type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[#"Year Month"]), "Year Month", "Value"),
    #"Filled Up" = Table.FillDown(#"Pivoted Column", Table.ColumnNames(#"Pivoted Column")),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([Moment of Change] = "2023-07"))
in
    #"Filtered Rows"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @FieldsG,

Result:

dufoq3_0-1706909297867.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwNzQwNDAwMjAyMjMAAiUdJUsqYUND3ERsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Long OP" = _t, #"2022-01" = _t, #"2022-02" = _t, #"2022-03" = _t, #"2022-04" = _t, #"2022-05" = _t, #"2022-06" = _t, #"2022-07" = _t, #"2022-08" = _t, #"2022-09" = _t, #"2022-10" = _t, #"2022-11" = _t, #"2022-12" = _t, #"2023-01" = _t, #"2023-02" = _t, #"2023-03" = _t, #"2023-04" = _t, #"2023-05" = _t, #"2023-06" = _t, #"2023-07" = _t, #"2023-08" = _t, #"2023-09" = _t, #"2023-10" = _t, #"2023-11" = _t, #"2023-12" = _t]),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(Source, {"Long OP"}, "Year Month", "Value"),
    AddedIndex = Table.AddIndexColumn(UnpivotedOtherColumns, "Index", 0, 1, Int64.Type),
    Ad_MomentOfChange = Table.AddColumn(AddedIndex, "Moment of Change", each try if [Value] = AddedIndex{[Index]-1}[Value] then null else [Year Month] otherwise null, type text),
    #"Added Custom" = Table.AddColumn(Ad_MomentOfChange, "Last Value Before Change", each if [Moment of Change] = null then null else Ad_MomentOfChange{[Index]-1}[Value], type text),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[#"Year Month"]), "Year Month", "Value"),
    #"Filled Up" = Table.FillDown(#"Pivoted Column", Table.ColumnNames(#"Pivoted Column")),
    #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([Moment of Change] = "2023-07"))
in
    #"Filtered Rows"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Greg_Deckler
Community Champion
Community Champion

@FieldsG Well, in either DAX or PQ, you likely want to unpivot your columns. Then maybe sort it and add an index and then you can grab the difference between the previous row and the current row. Then you just need to get the min date (Attribute) where the difference is not 0.

 

If you give up on a PQ solution, here is the DAX way to do it: https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739#M211



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.