cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Super User

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

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

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

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

so incase if you can help me further thank you

Super User

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

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

Announcements

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors