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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
mbylicki
Frequent Visitor

Compare Data based on 2 selected values in 1 column

Hi,

 

we're currently switching from Qlik into Power BI, and we're facing with such problem.

 

We load several files into one table (simple example below)

mbylicki_0-1605714844434.png

 

What we want to achieve is to allow user choose 2 different File names and compare (eg. subtract) all measures (Sell in the example).

In QlikView we had 2 list of 'File name' and use Alternate states.

 

In Power BI I tried to create 2 Fields with 'File name' each, create a Measure getting selected value from each, and finally use CALCULATE formula but I'm not able to put just created measure.

CALCULATE(sum('INPUT TABLE'[Sell]),'INPUT TABLE'[File name]="File B")-CALCULATE(sum('INPUT TABLE'[Sell]),'INPUT TABLE'[File name]="File A")

In other words how to make above red values dynamically choosing by user.

 

Here is excel based solution

 

I will appreciate any help

 

Thank you!

 

Maciej

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi @mbylicki ,

The Dax function of Selectvalue is suitable for single sign-on. It is suitable for when only one is selected, there will be a value, otherwise there will be no value

For example: I need to select a month and display the value of the previous month, this can use selectvalue

v-yangliu-msft_0-1605857123160.png

Dax formula:

Measure =
var _1=SELECTEDVALUE('Table'[month])
var _2=CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[month]=_1-1))
return _2

Put month into slice and measure into card. By selecting May, the amount in April is displayed

v-yangliu-msft_1-1605857123163.png

You can downloaded PBIX file from here.

Best Regards,

Liu Yang

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

v-yangliu-msft
Community Support
Community Support

Hi  @mbylicki ,

 

Here are the steps you can follow:

1. Create measure.

compara =
var _max = MAX('Table'[File name])
var _min = MIN('Table'[File name])

return CALCULATE(SUM('Table'[Sell]),ALLEXCEPT('Table','Table'[Client]),FILTER('Table','Table'[File name]=_max)) - CALCULATE(SUM('Table'[Sell]),ALLEXCEPT('Table','Table'[Client]),FILTER('Table','Table'[File name]=_min))

2. Result.

v-yangliu-msft_0-1605773391740.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

 

Thank you v-yangliu-msft

 

I modified Your solution using 2 independent slicers, so also measure You created in changed from "MAX/MIN" to "SELECTEDVALUE" but Your formula stoped working 😞 Could you please check what I'm doing wrong.

 

I share modified PBIX here 

 

Thank You!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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