cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Manvi1983
New Member

How to convert SQL case statement to dax

case
when (COALESCE(sum(ABC),0) - COALESCE(sum(ABCD),0)) < 0 then 0
else (COALESCE(sum(ABC),0) - COALESCE(sum(ABCD),0)) / sum(XYZ)

1 ACCEPTED SOLUTION

can you please show me the full measure how you wrote it

or please try 

Measure = 
VAR result = SUM('Table'[ABC]) - SUM('Table'[ABCD])
RETURN
IF(
    result < 0,
    0,
    DIVIDE(
        result,
        SUM('Table'[XYZ]),
        0 
    )
)

View solution in original post

3 REPLIES 3
eliasayyy
Super User
Super User

hello please try 

IF(
    CALCULATE(SUM('Table'[ABC])) - CALCULATE(SUM('Table'[ABCD])) < 0,
    0,
    DIVIDE(
        CALCULATE(SUM('Table'[ABC])) - CALCULATE(SUM('Table'[ABCD])),
        SUM('Table'[XYZ])
    )
)

Thank you for the reply. Somehow the last bit which is

SUM('Table'[XYZ])

is actually a measure and DAX is not picking up with this syntax and also coming with this error 

Manvi1983_0-1683019731844.png

so incase if you can help me further thank you 

can you please show me the full measure how you wrote it

or please try 

Measure = 
VAR result = SUM('Table'[ABC]) - SUM('Table'[ABCD])
RETURN
IF(
    result < 0,
    0,
    DIVIDE(
        result,
        SUM('Table'[XYZ]),
        0 
    )
)

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors