Forum Discussion

vidheesha's avatar
vidheesha
New Member
4 years ago
Solved

Stuck with the sum and if

Hi All,

 

I am trying to replicate the SQL case when statement in the Power BI as a calculated measure.

The SQL statement is 

 

(CASE WHEN 'Target Flag' = 'Actual' AND 'Date.FYear' = '2023'

THEN 'X.var'

ELSE 0 

END)

 

The calculated measure has to SUM the X.var if the above 

conditions are true

 

 

 

  • Hi, vidheesha ;

    Try it.

    measure =
    IF (
        MAX ( [Target Flag] ) = "Actual"
            && MAX ( [Date.FYear] ) = 2023,
        SUM ( [X.var] ),
        0
    )
    


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, vidheesha ;

    Try it.

    measure =
    IF (
        MAX ( [Target Flag] ) = "Actual"
            && MAX ( [Date.FYear] ) = 2023,
        SUM ( [X.var] ),
        0
    )
    


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.