Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
AliH
Frequent Visitor

Obtuse SQL Case statement to DAX

Hi All,

 

First post here - DAX is defeating me on this one. I know the basic SWITCH(), but I have a more complicated 'Switch' I'm trying to get working in DAX and hoping some guru here can help.

 

My case statement is as follows, and tracks what overall 'status' the business defines an order as.

Not copied exact SQL, just written the outline and a few exampes of the somewhat obtuse case, ther are some 15+ in total

 

CASE

    WHEN Status = T  AND (ShippingDate <= CURDATE() OR complete = 0) THEN "Trapping"

    WHEN Status = T AND (ShippingDate > CURDATE() OR Complete <> 0) THEN "FutureTrapping"
    WHEN Status = O and OrderType = Web THEN WebOpen
    WHEN Status = O AND NOT OrderType = Web THEN NonWebOpen

    WHEN Despatched = 0 AND Date(ShipDate) > DATE(NOW()) THEN "Future"

    WHEN (((Status IN ("P","H")) OR (((Status != X) AND Stopped = -1) OR (Packed = -1 AND complete = 0)) And Status <> T Then "Stopped/Parked"

And a bunch of others.

Eseentially I am trying to get a switch statement to work on a few columns, I think I might need Nested switches. But as I said, this is currently defeating me.

 

Any help is much appreciated.

 

Many thanks,

 

Ali H

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@AliH

 

Gotcha, that makes sense. I bet you could do this with a single SWITCH though. Something like:

 

CaseStatement =
SWITCH(
   TRUE(),
   AND(Status="T", OR(ShippingDate <= TODAY(), complete = 0)), "Trapping",
   AND(Status="T", OR(ShippingDate > TODAY(), complete <> 0)), "FutureTrapping"
)

With AND's and OR's, you can specify the same logic as your SQL. If all of these columns are in different tables, make sure to use RELATED if they have a valid relationship.

 

Hope this helps,

Parker

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hey @AliH

 

Are you connecting to a SQL datasource? If so, why not just leave your case statement in SQL and bring it in that way?

 

Thanks,

Parker

Hi Parker,

I should have perhaps mentioned. The business' main database is MySQL - I pull the data in to an MS SQL Warehouse with SSIS, via a staging database where I perform any data manipulations I require. I could have this case statement set the data in the MS SQL warehouse in the SSIS package. Which is what it looks like I will likely end up doing.

 

This package runs every minute and is very efficient. I don't like making changes to this package and was just hoping to be able to do this via DAX, for now at least. I'm DAX curious and am still learning, so like the challenge.

 

Many thanks,

 

Alister

Anonymous
Not applicable

@AliH

 

Gotcha, that makes sense. I bet you could do this with a single SWITCH though. Something like:

 

CaseStatement =
SWITCH(
   TRUE(),
   AND(Status="T", OR(ShippingDate <= TODAY(), complete = 0)), "Trapping",
   AND(Status="T", OR(ShippingDate > TODAY(), complete <> 0)), "FutureTrapping"
)

With AND's and OR's, you can specify the same logic as your SQL. If all of these columns are in different tables, make sure to use RELATED if they have a valid relationship.

 

Hope this helps,

Parker

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.