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
sriram74
Frequent Visitor

Power BI - Difference of a measure compared to Selection

Good Afternoon,

 

We have a location and a sales table. When the location is selected, it should list all values in table with a measure showing the difference of the sales based on the selection.

 

CountrySales
USA100
UK90
Canada85
Mexico110

 

When the slicer value of  'USA' (location) is selected. The result should be 

 

CountrySalesDiff
USA1000
UK9010
Canada8515
Mexico110-10

 

Where diff = Sales - ( Sales of the selected Country)

 

Thank You in advance for making the time to go through my post.

 

-Sriram

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

@sriram74 ,

 

You need to create another tabel "Selection" which has only one [Country] column. Then you can create the slicer based on the "Selection" table.

Capture.PNG 

 

Then create a measure using DAX below:

Diff = 
VAR Selected_Country = SELECTEDVALUE('Selection'[Country])
VAR Selected_Country_Sales = CALCULATE(MAX('Table'[Sales]), FILTER(ALL('Table'), 'Table'[Country] = Selected_Country))
VAR Current_Country_Sales = MAX('Table'[Sales])
RETURN
Selected_Country_Sales - Current_Country_Sales

1.PNG 

 

Community Support Team _ Jimmy Tao

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

5 REPLIES 5
v-yuta-msft
Community Support
Community Support

@sriram74 ,

 

You need to create another tabel "Selection" which has only one [Country] column. Then you can create the slicer based on the "Selection" table.

Capture.PNG 

 

Then create a measure using DAX below:

Diff = 
VAR Selected_Country = SELECTEDVALUE('Selection'[Country])
VAR Selected_Country_Sales = CALCULATE(MAX('Table'[Sales]), FILTER(ALL('Table'), 'Table'[Country] = Selected_Country))
VAR Current_Country_Sales = MAX('Table'[Sales])
RETURN
Selected_Country_Sales - Current_Country_Sales

1.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello v-yuta-msft,

 

This worked. Thank You!

 

-Sriram

KHorseman
Community Champion
Community Champion

Diff = CALCULATE( [Sales], ALL(NameOfTableHereTheCountryColumnIs)) - [Sales]





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

Proud to be a Super User!




Thank you both for making the time.

 

I am not sure where I am wrong. But i am not able to get the results i need.

 

ex1.jpg

Using KHorsemans suggesion, 

 

Diff = CALCULATE( sum([Sales]), ALL(Table2[country])) - sum(Table1[Sales])

 

i was able to get the list of all countries but the sales column showed only for the country selected. The difference hence was incorrect.

 

Using Levajar's suggestion of using Selected value,

 
Diffs = var _country = selectedvalue(Table2[country]) return sumx(filter(table1,Table1[country] = _country),[sales])

 

i was not able to get the list of all the countries and thier respective sales. Not sure if I misunderstood your suggestions.

 

Thanks Again!

 

 

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.