Forum Discussion

wpf_'s avatar
wpf_
Icon for Post Prodigy rankPost Prodigy
5 years ago
Solved

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. 

  • Anonymous's avatar
    Anonymous
    5 years ago

    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

    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: 

     

    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.

4 Replies

  • wpf_ 

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

    • wpf_'s avatar
      wpf_
      Icon for Post Prodigy rankPost Prodigy

      Fowmy 

       

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

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

      • Fowmy's avatar
        Fowmy
        Icon for Super User rankSuper User

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



  • Anonymous's avatar
    Anonymous
    Not applicable

    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

    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: 

     

    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.