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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RMDNA
Solution Sage
Solution Sage

Help: brute force translating weird SQL-like language into DAX

Hi all,

 

I'm migrating a client's dashboards off of another vendor's platform into Power BI. However, all the calculations are handled in this weird SQL-like language in the backend. I'm not too great at nesting, so could you help me translate a couple into DAX? I can use it as a benchmark for the rest. I've pre-formatted it for readability.

 

Spoiler
COUNT(tracking number) where OnTimeRateDate <>(empty value)
and Date (calldate)between _start of date selection and _end of date selection
and Status in (INVOICED, COMPLETED)
and Extended Status in ((empty value),CONFIRMED, PENDING CONFIRMATION, COMPLETED)
and IsScheduledDateChangeFlag=1), 0)
/
COUNT(tracking number) where Date (calldate)between _start of date selectionand _end of date selection
and Statusin (INVOICED, COMPLETED)
and Extended Status in ((empty value),CONFIRMED, PENDING CONFIRMATION, COMPLETED)
and IsScheduledDateChangeFlag=1 )

 

The true extent of the insanity is something like this:

 

Spoiler
select ifnull((select #of WO where  Status in (INVOICED, COMPLETED)
and Extended Status in ((empty value), CONFIRMED, PENDING CONFIRMATION,COMPLETED)
and IsCreatedCompleted=0),0)
+
ifnull((select SDCD - Timeline Grade where Status in (INVOICED, COMPLETED)
and Extended Status in ((empty value), CONFIRMED, PENDING CONFIRMATION,COMPLETED)),0)
+
ifnull((select #of WO where Status in (INVOICED, COMPLETED) and Extended Status in ((empty value), CONFIRMED, PENDING CONFIRMATION,COMPLETED) and IsScheduledDateChangeFlag=1),0)
+
ifnull((select ((ifnull((SELECT COUNT(Tracking#) where IsCompleted <>0 and Date (workorders-completiondate) between _start of date selection and _end of date selection), 0))
+
(ifnull((SELECT COUNT(Tracking#) where IsExpired <>0 and Date (completiondate)between _start of date selection and _end of date selection), 0)))),0)

I understand that it's mostly just a crazy string of AND()s in series, but getting the DAX syntax down is driving me nuts. If someone could translate these two, I can repurpose pieces of it in all the other calcs.

 

Thanks!

 

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @RMDNA 

transforms from 

COUNT(tracking number) where OnTimeRateDate <>(empty value)
and Date (calldate)between _start of date selection and _end of date selection
and Status in (INVOICED, COMPLETED)
and Extended Status in ((empty value),CONFIRMED, PENDING CONFIRMATION, COMPLETED)
and IsScheduledDateChangeFlag=1), 0)

 

[tracking number],[OnTimeRateDate],[calldate],[Status],Extended Status],[IsScheduledDateChangeFlag]

these are considered as columns in one table, (is my understanding right?)

"INVOICED","CONFIRMED" ...

are considered as text string,    (right?)

then i create a measure in Power BI Desktop as below,

Please Try this firstly, if it doesn't work, please let me know more details

Measure =
CALCULATE (
    COUNT[tracking number],
    FILTER (
        ALL ( tablename ),
        MAX([OnTimeRateDate]) <> BLANK ()
            && MAX([calldate]) <= [measure of _end of date selection]
            && MAX([calldate]) >= [measure of _start of date selection]
            && MAX([Status]) IN { "INVOICED", "COMPLETED" }
            && MAX([Extended Status]) IN { " ", "CONFIRMED", "PENDING CONFIRMATION", "COMPLETED" }
            && MAX([IsScheduledDateChangeFlag]) = 1
    )
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.