Forum Discussion
How do I create a measure that returns two different values based on condition
- 6 years ago
Hi simuruge
I create a simple sample. Please try the formulas to check if it is what you want.
- For this formula, if we don't select any values in slicer, it will return 0 by default.
Measure = VAR Selected_Version = SELECTEDVALUE ( 'Table 1'[Version] ) VAR a = SUMX ( 'Table', 'Table'[Plan] + IF ( 'Table'[Version] = Selected_Version, SUM ( 'Table'[Perf] ), 0 ) ) RETURN a- If you want to show other data without selecting, you could try this:
Measure 2 = VAR Selected_Version = SELECTEDVALUE ( 'Table 1'[Version] ) VAR a = SUMX ( 'Table', 'Table'[Plan] + IF ( 'Table'[Version] = Selected_Version, SUM ( 'Table'[Perf] ), 0 ) ) RETURN IF ( ISFILTERED ( 'Table 1'[Version] ), a, "No Filter" )For more details, please download my sample to have a try.
Hi simuruge
I create a simple sample. Please try the formulas to check if it is what you want.
- For this formula, if we don't select any values in slicer, it will return 0 by default.
Measure =
VAR Selected_Version =
SELECTEDVALUE ( 'Table 1'[Version] )
VAR a =
SUMX (
'Table',
'Table'[Plan]
+ IF ( 'Table'[Version] = Selected_Version, SUM ( 'Table'[Perf] ), 0 )
)
RETURN
a
- If you want to show other data without selecting, you could try this:
Measure 2 =
VAR Selected_Version =
SELECTEDVALUE ( 'Table 1'[Version] )
VAR a =
SUMX (
'Table',
'Table'[Plan]
+ IF ( 'Table'[Version] = Selected_Version, SUM ( 'Table'[Perf] ), 0 )
)
RETURN
IF ( ISFILTERED ( 'Table 1'[Version] ), a, "No Filter" )
For more details, please download my sample to have a try.
- simuruge6 years agoRegular Visitor
Hi, Thank you so much for the solution. Yes it works and what Nandu had mentioned also worked.
I made an error by pasting the formua in a calculated column. However, when I used a measure it worked fine.
Thank you both for extending your help.
Regards,
Sid
- v-xuding-msft6 years ago
Community Support
Hi simuruge ,
My formulas are both of measures. I'm glad that they works for you. 😊
Can you please accept the helpful answer as solution? Then we will be able to close the thread. More people who have the same request will benefit here.