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

View all the Fabric Data Days sessions on demand. View schedule

Reply
meozalp
Microsoft Employee
Microsoft Employee

DAX formula to provide variation within the same values of a single column

Hello,

 

This is my dataset:

Test ScenarioTestCategory 1Test Category 2
Test1510
Test269
Test378
Test434
Test51012
Test656
Test7910

 

I want to have a slicer and once either of the two test scenarios are selected, present the variation in results.

 

Test ScenarioTestCategory 1Test Category 2
Test1510
Test269
Variation20%-10%

 

How can I write a DAX measure that will calculate the Variation tab within the same column?

 

Thank you.

3 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @meozalp ,

 

A measure like this gets the result:

 

Value1 = 
var r = DISTINCTCOUNT('Table'[Test Scenario])
var v1 = SELECTEDVALUE('Table'[TestCategory 1])

var x1 = sumx(filter('Table', 'Table'[Test Scenario] = MIN('Table'[Test Scenario])),'Table'[TestCategory 1])
var x2 = sumx(filter('Table', 'Table'[Test Scenario] = Max('Table'[Test Scenario])),'Table'[TestCategory 1])

var result =
switch ( TRUE(),
r=1, v1,
r=2, FORMAT(DIVIDE(x1-x2,x1), "0%"),
"Too many tests selected")

return result

 

2020-07-18 02_02_48-Untitled - Power BI Desktop.png

So the assumption here is that the test with the lower number is the 100%, for value2 just copy the measure and change the [Test Category1] in [Category 2]

 

Jan

if this is a solution for you, don't forget to mark it as such. thanks

View solution in original post

Anonymous
Not applicable

Hello @meozalp 

 

The brackets in the formula are not in the right place.

 

var x1 = SUMX(FILTER('TestResultNtttcp','TestResultNtttcp'[TestScenario] = MIN('TestResultNtttcp'[TestScenario])),'TestResultNtttcp'[cpu])
var x2 = SUMX(FILTER('TestResultNtttcp','TestResultNtttcp'[TestScenario] = MAX('TestResultNtttcp'[TestScenario])),'TestResultNtttcp'[cpu])
 
Regards,
 
Jan

View solution in original post

AntrikshSharma
Super User
Super User

Download the PBI file from here: https://drive.google.com/file/d/1DSD_wjlDUu9Oibx8FSfwwreAHYrZMMd1/view?usp=sharing

I added an index column to do the calculations.

 

1.PNG

View solution in original post

5 REPLIES 5
AntrikshSharma
Super User
Super User

Download the PBI file from here: https://drive.google.com/file/d/1DSD_wjlDUu9Oibx8FSfwwreAHYrZMMd1/view?usp=sharing

I added an index column to do the calculations.

 

1.PNG

@AntrikshSharma @Anonymous Thanks a lot for your help.

Anonymous
Not applicable

Hello @meozalp 

 

The brackets in the formula are not in the right place.

 

var x1 = SUMX(FILTER('TestResultNtttcp','TestResultNtttcp'[TestScenario] = MIN('TestResultNtttcp'[TestScenario])),'TestResultNtttcp'[cpu])
var x2 = SUMX(FILTER('TestResultNtttcp','TestResultNtttcp'[TestScenario] = MAX('TestResultNtttcp'[TestScenario])),'TestResultNtttcp'[cpu])
 
Regards,
 
Jan
meozalp
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

Thanks a lot for the prompt reply.

I am getting an error: Too few arguments were passed to the SUMX function. Could you please help reviewing it?

 

Value1 =
var r = DISTINCTCOUNT('TestResultNtttcp'[TestScenario])
var v1 = SELECTEDVALUE('TestResultNtttcp'[cpu])
var x1 = SUMX(FILTER('TestResultNtttcp','TestResultNtttcp'[TestScenario] = MIN('TestResultNtttcp'[TestScenario],'TestResultNtttcp'[cpu])))
var x2 = SUMX(FILTER('TestResultNtttcp','TestResultNtttcp'[TestScenario] = MAX('TestResultNtttcp'[TestScenario],'TestResultNtttcp'[cpu])))

var result =
SWITCH( TRUE(),
r=1, v1,
r=2, FORMAT(DIVIDE(x1-x2,x1), "0%"),
"Too many tests selected")

return result

 

Melih

Anonymous
Not applicable

Hi @meozalp ,

 

A measure like this gets the result:

 

Value1 = 
var r = DISTINCTCOUNT('Table'[Test Scenario])
var v1 = SELECTEDVALUE('Table'[TestCategory 1])

var x1 = sumx(filter('Table', 'Table'[Test Scenario] = MIN('Table'[Test Scenario])),'Table'[TestCategory 1])
var x2 = sumx(filter('Table', 'Table'[Test Scenario] = Max('Table'[Test Scenario])),'Table'[TestCategory 1])

var result =
switch ( TRUE(),
r=1, v1,
r=2, FORMAT(DIVIDE(x1-x2,x1), "0%"),
"Too many tests selected")

return result

 

2020-07-18 02_02_48-Untitled - Power BI Desktop.png

So the assumption here is that the test with the lower number is the 100%, for value2 just copy the measure and change the [Test Category1] in [Category 2]

 

Jan

if this is a solution for you, don't forget to mark it as such. thanks

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.