Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
For illustration purpose, i am using excel but the solution i need is for Power BI. Also, this is a small sample used as an example, my real data is quite huge.
I have 3 columns (image below)
I loaded it into Power BI and trying to create a matrix table with 'Metric' as column and 'Spend' as value. So i should get some output (image below)
Now i need to add a third column in this matrix table named "Difference" that dynamically calculates the difference between the values in Target and Actuals columns. In this example it should be 0.
How to create such column in matrix table in Power BI?
Alternatively, in the query editor, you can remove "Region", pivot on Metric, rename "Actual" to "Actuals", go to "Add Column", select both columns and choose option Standard - Subtract. Adjust the generated code to have the new column named "Difference".
Code generated (the first line is specific for me entering data):
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcizOTFTSUQpJLEpPLQEyDA0MlGJ14OKOySWliTlAhgVUODe1KDMZVYcRuhRck6EJUCoWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Region = _t, Metric = _t, Spend = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Region", type text}, {"Metric", type text}, {"Spend", type number}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Region"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Metric]), "Metric", "Spend", List.Sum), #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Actual", "Actuals"}}), #"Inserted Subtraction" = Table.AddColumn(#"Renamed Columns", "Difference", each [Target] - [Actuals], type number) in #"Inserted Subtraction"
I'm not sure that your data is in the best format for what you are trying to accomplish, but you could do something like this and add it to Value area:
Measure = CALCULATE(SUM(Difference[Spend]),Difference[Metric]="Target") - CALCULATE(SUM(Difference[Spend]),Difference[Metric]="Actual")
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
81 | |
66 | |
58 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |