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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SARAHCH
Frequent Visitor

Calculate difference between two rows in a matrix

Hello,
I want to calculate the difference between the two rows, and display it in the 3rd line, any suggestions please?

While knowing that the value is a sum revenue MTD (month to day), the goal is to display the income of each year according to the months as well as the variation between the month of the current year and the previous year.

 

SARAHCH_2-1709222010369.png

Thank you,

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @SARAHCH 

 

Please try this:

First of all, I create a set of sample:

vzhengdxumsft_0-1709262323968.png

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:

vzhengdxumsft_1-1709262442116.png

 

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.

View solution in original post

6 REPLIES 6

Nice to see you found a solution that fits you!

You may also want to check out this new feature (Mostly Versus Previous) 

Getting started with Visual Calcs in Power BI

https://www.youtube.com/watch?v=eDRgzEVwVEc

v-zhengdxu-msft
Community Support
Community Support

Hi @SARAHCH 

 

Please try this:

First of all, I create a set of sample:

vzhengdxumsft_0-1709262323968.png

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:

vzhengdxumsft_1-1709262442116.png

 

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:

Daniel_PowerBI_0-1709225169837.png

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:

Daniel_PowerBI_1-1709225247145.png

Let me know if that's what you were looking for.

Regards

 

Please mark as solution if approuved 

SARAHCH
Frequent Visitor

Yes !!

Daniel29195
Super User
Super User

@SARAHCH 

so you need under 2022, 2023 , a row stating the income, and another row stating the variance ? 

correct ? 

 

Yes ! I need under 2022 , 2023 a row stating the come, and another row stating the variance. 
this is my exemple : 

SARAHCH_0-1713194874828.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.