Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Measure with different outputs based on condition

Hi   I want to create a measure that calculates based on a condition: If Table1[Column1] = "KPI1" then Formula1 else Formula2. The logic is very simple, but I can't get Power BI to read Table[Colu...
  • Greg_Deckler's avatar
    4 years ago

    Anonymous Try:

    Measure =
      IF(
        MAX('Table1'[Column]="KPI1",
        DIVIDE(Sum(Num), Sum(Den), 0),
        DIVIDE(Sum(Num), Average(Den), 0)
      )
  • edhans's avatar
    4 years ago

    Try this Anonymous 

    MeasureName =
    VAR varValue =
        MAX( TableName[Field] )
    RETURN
        IF(
            varValue = "KPI1",
            DIVIDE(
                SUM( Table[Num] ),
                SUM( Table[Den] ),
                0
            ),
            DIVIDE(
                SUM( Table[Num] ),
                AVERAGE( Table[Den] ),
                0
            )
        )
    

    You need to convert the field to a scalar value, which MAX does when used like this. MIN will give you the same result.