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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Difference column in a matrix

Hi,

i'd calculate the difference in a matrix between values from the same column [HRS_PLAN_DELTA], for each IDS in the same date, for different ID_Report.
difference.PNG

Do you have some ideas ? 

Dom

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

To pivot the table and add a custom column in power query can get the excepted result we need. M code for your refernce.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc7LCUAhDETRXrIWdEafn1rE/ttQwgskCyFwSK57CwhJoi8js2C98ZOTjKhEo+6oKlWj6agpNSPgN+r1EAOd9VjDcDZizq/NmHs/ORc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, IDS = _t, Date = _t, HRS_PLAN_DELTA = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"IDS", Int64.Type}, {"Date", type date}, {"HRS_PLAN_DELTA", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"IDS"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"ID", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"ID", type text}}, "en-US")[ID]), "ID", "HRS_PLAN_DELTA", List.Sum),
    #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Custom", each [121]-[122])
in
    #"Added Custom"

 

Capture.PNG

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

This is quite similar in principle to this solution: https://community.powerbi.com/t5/Desktop/Difference-between-rows-with-different-categories/m-p/65702... - you could try using this type of solution to search for the row values to compare. 

 

However, you will have to be more specific on what you are trying to achieve to get a solution that works. 

Can you show your expected result and the working for one example? 

Anonymous
Not applicable

Hi,
i'd a result like this:
DIFFERENCE1.PNG

 


Dom

Anonymous
Not applicable

If you can paste you data in that would be great
Anonymous
Not applicable

@Anonymous 
DIFFERENCE1.PNG

Hi @Anonymous ,

 

To pivot the table and add a custom column in power query can get the excepted result we need. M code for your refernce.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc7LCUAhDETRXrIWdEafn1rE/ttQwgskCyFwSK57CwhJoi8js2C98ZOTjKhEo+6oKlWj6agpNSPgN+r1EAOd9VjDcDZizq/NmHs/ORc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, IDS = _t, Date = _t, HRS_PLAN_DELTA = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"IDS", Int64.Type}, {"Date", type date}, {"HRS_PLAN_DELTA", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"IDS"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"ID", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"ID", type text}}, "en-US")[ID]), "ID", "HRS_PLAN_DELTA", List.Sum),
    #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Custom", each [121]-[122])
in
    #"Added Custom"

 

Capture.PNG

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

I've created this measure: 

DIFFERENCE = 
var min_id_report = MIN(COPR_RECAP[REVISION])
var max_id_report = MAX(COPR_RECAP[REVISION])
return CALCULATE(SUM(COPR_DETAIL[HRS_PLAN_DELTA]); COPR_RECAP[REVISION]=min_id_report) - CALCULATE(SUM(COPR_DETAIL[HRS_PLAN_DELTA]);COPR_RECAP[REVISION]=max_id_report)

The result is ok for 2 [Revisions]
I'd create a difference between a fixed [Revision] and the other ones (3 or 4 revisions).
Do you have some ideas ? 

Anonymous
Not applicable

You could do the following:

1. Create a new Calculated Table:

Distinct Revisions = distinct(COPR_RECAP[REVISION])
2. Create a new Measure:
vs Selected Revision = 
SUM(COPR_DETAIL[HRS_PLAN_DELTA])
-
IF(
  HASONEVALUE('Distinct Revisions'[REVISION]) = FALSE(), 0,
  CALCULATE(
    SUM(COPR_DETAIL[HRS_PLAN_DELTA]),
    COPR_DETAIL[REVISION] = VALUES('Distinct Revisions'[REVISION])
  )
)

3. Add a slicer visual with 'Distinct Revisions'[REVISION]

     and Add [vs Selected Revision] to your visual.

4. Or, Add both 'Distinct Revisions'[REVISION] and [vs Selected Revision] to your visual.

5. You made to tweak, add information as necessary, but this pattern should generally work for comparing against a certain value.

Hope this helps,

Nathan

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.