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

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.

Reply
dax_bee
Frequent Visitor

Subtraction of Measures across different rows

Hi.

 

I have an issue I am currently unable to resolve, so any help would be greatly appreciated.  I am trying to perform calculations across measures/date ranges and storing the result against a specific data/category value.

 

Using the table below as an example, I am trying to calculate the "Value" column.  Basically multiple the values for Measure 1 & Measure 2 for a specific Year/Category (i.e. 2015, Cat 1) & subtract the corresponding values for Measure 1 * Measure 2 for Year/Category = 2014, Cat1.  The table shows the values i need to use within the calculation.

 

PowerBI Measure Subtraction.png

 

 

PowerBI Measure Subtraction Example.png 

 

 

 

 

1 ACCEPTED SOLUTION
Baskar
Resident Rockstar
Resident Rockstar

Try this , If u don't want calculated column go with Measure 

 

 

Value_1 =
var Cur_Category = CONCATENATEX(VALUES(Table4[Category]),Table4[Category],",")

 

var Measures_2014 = CALCULATE(SUM(Table4[Measure1]) * SUM(Table4[Measure2]),FILTER(ALL(Table4),AND(Table4[Year]=2014,Table4[Category]=Cur_Category)))

 

return
CALCULATE( SUM(Table4[Measure1]) * SUM(Table4[Measure2] )) - Measures_2014

 

 

It also give u the same result which i mention in previous post , but it is not column it is measure .

 

 

 

View solution in original post

7 REPLIES 7
Baskar
Resident Rockstar
Resident Rockstar

Try this , If u don't want calculated column go with Measure 

 

 

Value_1 =
var Cur_Category = CONCATENATEX(VALUES(Table4[Category]),Table4[Category],",")

 

var Measures_2014 = CALCULATE(SUM(Table4[Measure1]) * SUM(Table4[Measure2]),FILTER(ALL(Table4),AND(Table4[Year]=2014,Table4[Category]=Cur_Category)))

 

return
CALCULATE( SUM(Table4[Measure1]) * SUM(Table4[Measure2] )) - Measures_2014

 

 

It also give u the same result which i mention in previous post , but it is not column it is measure .

 

 

 

is it possible to add a lookupvalue function in here? if the year is represented by a index number. can we add a lookupvalue function to lookup the index in another year table then put the lookuped value into the calculation? 

Hi Baskar.

 

Thank you very much for resolving my issue, I really apreciate it...

 

 

Baskar
Resident Rockstar
Resident Rockstar

Cool ,

 

For my assumption do u want multiple the measure1 and measure2 then subtract with 2014 Data ? am right ?

 

Create one Calculated Column like the image .

 

1.JPG

 

 

 

Try this, if it is not helping u let me know i will help u .

 

 

tringuyenminh92
Memorable Member
Memorable Member

Hi @dax_bee,

 

This expectation could be achieve by calculated measure or calculated column:

  • Create Value - Calculated Measure: 
Value (Calculated Measure) = CALCULATE( SUM(data[M1])*SUM(data[M2]),filter(data,data[Year]= MAX( data[Year]) ))  - CALCULATE( SUM(data[M1])*SUM(data[M2]),filter(ALLEXCEPT(data,data[Category]),data[Year]=MAX(data[Year])-1 ))

(you could create seperate measure to understand each formula)

 

  • Or could create Value - Calculated Column:
Value (Calcualted Column) = data[M1]*data[M2] - CALCULATE(sum(data[M1])*sum(data[M2]),filter(ALLEXCEPT(data,data[Category]),data[Year]=EARLIER(data[Year])-1 ))

 

Screenshot 2016-12-31 22.22.07.png

 

Please check sample file and sample data for observation and choose one of 2 ways.

 

If this works for you please accept it as solution and also like to give KUDOS.

Best regards
Tri Nguyen

Hi Tri.

 

Thanks for responding to my post.  I have looked at the solution and have the following queries, based upon my inital example;

 

1. M1 & M2 are both caluclated measures.  Hence I am not able to select them within the Sum function, my understanding is that only "Columns" can be selected?

 

2. The value column for Year=2016 & Category=Cat 1 needs to subtract the value from 2014 Cat 1 (10 * 20) and not the value from 2015 Cat 1 which is what I think you have assumed in your solution (i.e. Year -1)?

 

 

 

 

Baskar
Resident Rockstar
Resident Rockstar

If M1 and M2 is calculated measure , no need to add sum in front of M1and M2 . u can use as direct M1 and M2

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.