Forum Discussion
Calculate difference between two rows in a matrix
- Anonymous2 years ago
Hi SARAHCH
Please try this:
First of all, I create a set of sample:
Then add a new table, the value of the table is the field you want to show in the matrix:
Table 2 = {"2022","2023","Variance"}Then add a measure:
Measure = VAR _newValue = SELECTEDVALUE('Table 2'[Value]) RETURN SWITCH( _newValue, "2022",CALCULATE(SUM('Table'[value]),YEAR('Table'[Date])=2022), "2023",CALCULATE(SUM('Table'[value]),YEAR('Table'[Date])=2023), "Variance",CALCULATE(SUM('Table'[value]),YEAR('Table'[Date])=2023)-CALCULATE(SUM('Table'[value]),YEAR('Table'[Date])=2022) )The result is as follow:
If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello SARAHCH ,
Maybe you could try something like this:
sales amount sum = SUM(FactInternetSales[SalesAmount])
sales amount previous = CALCULATE(SUM(FactInternetSales[SalesAmount]), SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))
sales amount variance = FactInternetSales[sales amount sum] - [sales amount previous]where you calculate the sum of year, previous and the variance and switch the measures to appear as rows like so:
Let me know if that's what you were looking for.
Regards
Please mark as solution if approuved