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
simuruge
Regular Visitor

How do I create a measure that returns two different values based on condition

Hi,

 

I am trying to trplicate a formula in Tableau like, ([Plan $] + IIF([Version]=[Version Toggle],[Perf $],0))

 

[Version] is a column in a table

[Version Toggle] is a dynamic value where the user can toggle between two values.

In PoweBI , I will use selected value to get the value selected by user.

 

Since Power BI measure returns only one value, I could not use formula like below,

 

sum([Plan $]) + If ( values([table.version]) = selectedvalue([Version Toggle]), sum([Perf $]) , 0)

 

Sample values: 

Version = 000, 001, 003, 004

Version Toggle values ,  000, 001

 

So, how do I achieve it?

 

Thanks in advance.

 

 

 

 

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

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" )

1.PNG2.PNG

 

For more details, please download my sample to have a try.

 

Best Regards,
Xue Ding
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

4 REPLIES 4
v-xuding-msft
Community Support
Community Support

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" )

1.PNG2.PNG

 

For more details, please download my sample to have a try.

 

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

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

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.

 

 

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

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.