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
wpf_
Post Prodigy
Post Prodigy

How to execute two values in if expressions?

How can i execute 2 values in if expressions?  for example:

 

If(x=1, 

Do A &&

Do B,

else do C

)

 

Thanks. 

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

Hi @wpf_ ,

 

If you want to execute two values, you must ensure that one result is returned. The metric returns an aggregate value, not multiple values.

 

I am not sure what your Do A&&Do B means, if you want to return two results, it won’t work, unless you merge the two results in text format, as follows

Sample data

11.png

Measure =
IF (
    MAX ( 'Table'[x] ) = 1,
    CALCULATE ( SUM ( 'Table'[Num] ), 'Table'[User] = "A" ) & ","
        & CALCULATE ( SUM ( 'Table'[Num] ), 'Table'[User] = "B" ),
    CALCULATE ( SUM ( 'Table'[Num] ), 'Table'[User] = "C" )
)

& is used to connect two results, &","& can be a comma between the two results.

 

Result: 

12.png

 

If you're still confused, you can provide sample data and expected results like me.

 

Best Regards,

Stephen Tao

 

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-stephen-msft
Community Support
Community Support

Hi @wpf_ ,

 

If you want to execute two values, you must ensure that one result is returned. The metric returns an aggregate value, not multiple values.

 

I am not sure what your Do A&&Do B means, if you want to return two results, it won’t work, unless you merge the two results in text format, as follows

Sample data

11.png

Measure =
IF (
    MAX ( 'Table'[x] ) = 1,
    CALCULATE ( SUM ( 'Table'[Num] ), 'Table'[User] = "A" ) & ","
        & CALCULATE ( SUM ( 'Table'[Num] ), 'Table'[User] = "B" ),
    CALCULATE ( SUM ( 'Table'[Num] ), 'Table'[User] = "C" )
)

& is used to connect two results, &","& can be a comma between the two results.

 

Result: 

12.png

 

If you're still confused, you can provide sample data and expected results like me.

 

Best Regards,

Stephen Tao

 

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

Fowmy
Super User
Super User

@wpf_ 

Without enough information, it is really hard to suggest a solution. could explain your question with practical examples?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy 

 

how can I execute A and B when x=1?

notmally I can only execute just one value at a time.  

@wpf_ 

The output will be a single result form the if condition because it returns a scaler value: 

If can be simple check 

Price Group =
IF(
    'Product'[List Price] < 500,
    "Low",
    "High"
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.