Forum Discussion

mokhawaja's avatar
mokhawaja
Frequent Visitor
9 years ago
Solved

If function cannot check inside a column

Hi,

pretty exicted for the first post in Power BI forums :smileyvery-happy:

 

i am trying to create a measure based on an if function which should check inside a column called "Class" which has 3 values (A, B, C), then return the value form a measure A if the class is A and return the value from Measure B if the Class is B... so what i am trying to write as a function is the following:

 

If(Classes[Class] = "A", [Coverage A KPI], If(Classes[Class] = "B", [Coverage B KPI], 0))

 

so my problem is the if function cannot see the column Class to check inside it... while i could do it easily on Excel but it does not work in Power BI

 

 

 

so please advise how to work it out.

Regards,

Mohammad Alkhawaja

  • mokhawaja's avatar
    mokhawaja
    9 years ago

    the error is gone but it does not give me the right results (it gives me all zeros!)

     

    i re-tried the if function using measure inside the Classes table but also had to wrap it into a MAX function: and now it works perfectly 

     

    Measure =
    IF (
        MAX ( Classes[Class] ) = "A", [Coverage A KPI],
        IF ( MAX ( Classes[Class] ) = "B", [Coverage B KPI],
        0 )
    )

    really appreciate your time and help

     

    Best Regards,

    Mohammad

9 Replies

  • vanessafvg's avatar
    vanessafvg
    Community Champion

     

    mokhawaja

     

    Value =
    SWITCH (
        Classes[Class],
        Classes[Class] = "A", [Coverage A KPI],
        Classes[Class] = "B", [Coverage B KPI],
        Classes[Class] = "C", [Coverage C KPI],
        0
    )

     

    • mokhawaja's avatar
      mokhawaja
      Frequent Visitor

      thank you vanessafvg,

      really appreciate your help... i used your suggested formula and it showed me the below error:

       

       

      kindly advise,

      Regards

      Mohammad