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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mscla
Advocate I
Advocate I

Take the diferrence between two parameter

Hi everyone,

I created two parameters with lists of measures, two slicers and one matrix with these parameters.

My question is, Is it possible to create a measure to calculate the difference between two measures selected in slicer parameters?

I created this measures and don't bring me error messages

Diff_P1_P2 =
var Paramter1 = CALCULATE(SELECTEDVALUE(_Parameter_P1[_Parameter_Measures]))
var Paramter2 = CALCULATE(SELECTEDVALUE(_Parameter_P2[_Parameter_Measures2]))
RETURN
Paramter1-Paramter2
 
But, when I drag into pivot, show me this: 
"Columns [_Parameter_P1[_Parameter_MeasuresPivot] is part of composite key, but not all columns of the composite key are included in the expression or its depende expression"
2 ACCEPTED SOLUTIONS
v-yangliu-msft
Community Support
Community Support

Hi  @mscla ,

 

I created some data:

If you want to add a row to a matrix Row, you need to create a new table column as a Row, and then create a measure that uses the switch() function to determine the value corresponding to each value.

vyangliumsft_0-1709529861620.png

 

Here are the steps you can follow:

1. Enter data – create a table.

vyangliumsft_1-1709529861620.png

According to the Power BI design, the default sorting is alphabetical, so we need an Index to customize the sorting.

[Group] – Column tools – Sort by column – [lndex]

vyangliumsft_2-1709529884028.png

2. Create measure.

Test =
SWITCH(
    TRUE(),
     MAX('Row_Group'[Group])="MEASURE1",[Parameter_Measures],
     MAX('Row_Group'[Group])="MEASURE2",[Parameter_Measures2],
    MAX('Row_Group'[Group])="DIFFERENCE",[Parameter_Measures] - [Parameter_Measures2])

3. Result:

 

vyangliumsft_3-1709529884034.png

If it doesn't meet your desired outcome, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

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

View solution in original post

Hi my friend,

I really liked your idea, but I got a simpler solution.

The measurements are then based on a single table that isn't that big, so I made a copy of the table and created similar versions of the measurements,
like this

table 1 and measurements: 1, 2, 3
table 1a and measurements: 1a, 2a, 3a

So I created the parameters for measurements.

 

but thanks for all

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @mscla ,

 

I created some data:

If you want to add a row to a matrix Row, you need to create a new table column as a Row, and then create a measure that uses the switch() function to determine the value corresponding to each value.

vyangliumsft_0-1709529861620.png

 

Here are the steps you can follow:

1. Enter data – create a table.

vyangliumsft_1-1709529861620.png

According to the Power BI design, the default sorting is alphabetical, so we need an Index to customize the sorting.

[Group] – Column tools – Sort by column – [lndex]

vyangliumsft_2-1709529884028.png

2. Create measure.

Test =
SWITCH(
    TRUE(),
     MAX('Row_Group'[Group])="MEASURE1",[Parameter_Measures],
     MAX('Row_Group'[Group])="MEASURE2",[Parameter_Measures2],
    MAX('Row_Group'[Group])="DIFFERENCE",[Parameter_Measures] - [Parameter_Measures2])

3. Result:

 

vyangliumsft_3-1709529884034.png

If it doesn't meet your desired outcome, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

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

Hi my friend,

I really liked your idea, but I got a simpler solution.

The measurements are then based on a single table that isn't that big, so I made a copy of the table and created similar versions of the measurements,
like this

table 1 and measurements: 1, 2, 3
table 1a and measurements: 1a, 2a, 3a

So I created the parameters for measurements.

 

but thanks for all

mscla
Advocate I
Advocate I

Hi Greg, thanks for replay
I really don't need CALCULATE, you are right!
So, my goal is to create a row in the matrix that shows the difference between measures (single selection forced)

Presentazione standard1.jpg

 

Is there an easy way to do that?

 
Greg_Deckler
Super User
Super User

@mscla Well, for starters, there is no need for CALCULATE in your expression. The error seems to be referring to some other measure or something. The error is probably very dependent on the context of your visual.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.