cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rewind
Helper I
Helper I

Difference between 2 values in a table

I'm new to PowerBI and only basic understanding of DAX....

 

I would like to calculate the difference between two values in the same column. In this case I'm only interested in the difference between two jurisdictions at any one time (e.g. I'm interested in the difference between NSW and AUS only)

 

For example, if a user selects the Jurisdiction NSW and AUS the calculated column would show the difference between them (in this case I would expect +4.1)

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User IV
Super User IV

First, if you want user interaction to influence the calculation, then you cannot use a calculated column, you would need to use a measure. Second, you will need to use slicers that are not related to your table. Easiest way to do that would be to use Create Table from the modeling tab and use:

DISTINCT('Table'[Jusisdiction])

Check your relationships view and make sure that they are not related to your main table. Now that you have that, you can then create a measure like:

Measure = 
VAR __slicer1 = MAX('Slicer1'[Jurisdiction])
VAR __slicer2 = MAX('Slicer2'[Jurisdiction])
VAR __value1 = MAXX(FILTER('Table',[Jurisdiction]=__slicer1),[Mean])
VAR __value2 = MAXX(FILTER('Table',[Jurisdiction]=__slicer2),[Mean])
RETURN
__value1 - __value2

Something along those lines.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Greg_Deckler
Super User IV
Super User IV

First, if you want user interaction to influence the calculation, then you cannot use a calculated column, you would need to use a measure. Second, you will need to use slicers that are not related to your table. Easiest way to do that would be to use Create Table from the modeling tab and use:

DISTINCT('Table'[Jusisdiction])

Check your relationships view and make sure that they are not related to your main table. Now that you have that, you can then create a measure like:

Measure = 
VAR __slicer1 = MAX('Slicer1'[Jurisdiction])
VAR __slicer2 = MAX('Slicer2'[Jurisdiction])
VAR __value1 = MAXX(FILTER('Table',[Jurisdiction]=__slicer1),[Mean])
VAR __value2 = MAXX(FILTER('Table',[Jurisdiction]=__slicer2),[Mean])
RETURN
__value1 - __value2

Something along those lines.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Thank you! This worked with no issues 🙂

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.