cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Difference between 2 rows using first row fixed

Hello!

 

I need to calculate the difference between two rows in a matrix table in Power BI, but I need to keep the first row as reference, like this:

 

EDIT: The first row (Model "A") can be changed by filter, so I need to use always the first row, not the model as reference.

 

modelpricediffexplanation
A14990-
B1949450EXP.: MODEL B - MODEL A
C1799300EXP.: MODEL C - MODEL A
D26991200EXP.: MODEL D - MODEL A

 

I used a metric to calculate this values:

 

.AVG_PRICE = CALCULATE(AVERAGE(FORMULARIO_RESPOSTAS[DES_RESPOSTA_QTD]);FORMULARIO_RESPOSTAS[DES_RESPOSTA_QTD] > 0)
 
Anyone knows how can I get this?
 
Thanks!
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Difference between 2 rows using first row fixed

Hi @gonnelli,

 

Does that make sense? If so, kindly mark my answer as a solution to close the case.


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
Highlighted
Regular Visitor

Re: Difference between 2 rows using first row fixed

Have you tried using the LOOKUPVALUE function? You can use this to return the value for Model A in whatever column you need to reference. 

 

In your example below, the formula would look something like (I'm using "Table1" as the table where your values are stored in this example):

 

diff = CALCULATE(AVERAGE(Table1[price])-LOOKUPVALUE(Table1[price],Table1[model],"A"))
 
Put this measure as the diff column in your matrix table visual and you should get the desired results.
Highlighted
Super User IV
Super User IV

Re: Difference between 2 rows using first row fixed

Hi,

 

Do you want to take the difference between the price in the current row and the row with the minumum price?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Highlighted
Community Support
Community Support

Re: Difference between 2 rows using first row fixed

Hi @gonnelli,

 

Two ways you can choose.

 

1. To create a calculated column.

 

diffc = Table1[price]-CALCULATE(SUM(Table1[price]),FILTER(ALL(Table1),Table1[model]="A"))

2. To create a measure.

 

diffm = MAX(Table1[price])-CALCULATE(SUM(Table1[price]),FILTER(ALL(Table1),Table1[model]="A"))

Capture.PNG

For more details, please check the pbix as attached.

 

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.
Highlighted
Frequent Visitor

Re: Difference between 2 rows using first row fixed

Hello @v-frfei-msft

In my case, I can't use lookupvalues because the first "model" can be changed by filters.

 

I need to calculate always the difference between the first row with another rows.

Highlighted
Frequent Visitor

Re: Difference between 2 rows using first row fixed

Hi @Ashish_Mathur!

 

I need to calculate always the first rows and another rows, but the first rows can be changed by filter.

Highlighted
Community Support
Community Support

Re: Difference between 2 rows using first row fixed

Hi @gonnelli,

 

I made an update of the measure.

 

diffm = MAX(Table1[price])-CALCULATE(SUM(Table1[price]),FILTER(ALLSELECTED(Table1),Table1[model]=MINX(ALLSELECTED(Table1),Table1[model])))

Capture.PNG

 

For more details, please check the pbix as attached.

 

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.
Community Support
Community Support

Re: Difference between 2 rows using first row fixed

Hi @gonnelli,

 

Does that make sense? If so, kindly mark my answer as a solution to close the case.


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

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors