Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Store "IF" condition in variable

Hi,

 

I'm wondering, is power bi capable to store IF conditions in a variable?

example

 

 

 

var kondisi = 1 //using a dropdown, it will change value either 1 or 2

VAR param_kondisi = 
    IF(kondisi = 1,
      'Table'[Population 1] <> BLANK(),
      'Table'[Population 2] <> BLANK()
     )

Var Calculate_Result =
    CALCULATE(
        COUNT('Table'[primkey]),
        KEEPFILTERS(
            'Table'[client_name] = "Superman"
            && param_kondisi

        )
    )

 

 

 

any suggestion would be very appreciated,

thank you

5 Replies

  • Anonymous , it should return true or false

     

    try like

    Calculate_Result =
    CALCULATE(
    COUNT('00. SPK'[primkey]),
    KEEPFILTERS(
    'Table'[client_name] = "Superman"
    && ((kondisi = 1 && 'Table'[Population 1] <> BLANK()) || (kondisi <> 1 && 'Table'[Population 2] <> BLANK()))

    )
    )

    • Anonymous's avatar
      Anonymous
      Not applicable

      thanks! it returns correctly

      but is there any chance that pattern as I mentioned earlier, is possible in power bi?

       

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

        Anonymous , Just make sure it returns true or false

         

        like

        IF(kondisi = 1,
        if('Table'[Population 1] <> BLANK(),true(), false())
        if('Table'[Population 2] <> BLANK(),true(), false())
        )