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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
mtran1210
Regular Visitor

Convert SQL query to DAX

I have this query in SQL. 

 

LeadTimeMetPctCurrentPeriod = COALESCE(CAST(CASE WHEN TotalOrdersLTMetPeriodToDate = 0 OR TotalOrderUnitsPeriodToDate = 0 THEN 0
ELSE 1 - (CAST(TotalOrdersLTMetPeriodToDate AS DECIMAL(19,3)) / CAST(TotalOrderUnitsPeriodToDate AS DECIMAL(19,3)))
END AS DECIMAL(19,3)), 0)

COALESCE(SUM(CASE WHEN dte.IsPeriodToDate = 'Yes' AND dte.IsCurrentPeriod = 'Yes' THEN MetLeadTime ELSE 0 END), 0) AS TotalOrdersLTMetPeriodToDate

COALESCE(SUM(CASE WHEN dte.IsPeriodToDate = 'Yes' AND dte.IsPreviousPeriod = 'Yes' THEN MetLeadTime ELSE 0 END), 0) AS TotalOrdersLTMetPreviousPeriodToDate

 

 

How do I convert this to a DAX measure?

1 REPLY 1
MFelix
Super User
Super User

Hi @mtran1210 ,

 

Are this several columns on your SQL or a single column? It seems that you are making use of several columns.

 

In this case you would need something similar to this:

LeadTimeMetPctCurrentPeriod =
COALESCE (
    IF (
        Table.[TotalOrdersLTMetPeriodToDate] = 0
            || Table.[TotalOrderUnitsPeriodToDate] = 0,
        0,
        1
            - DIVIDE (
                ( Table.[TotalOrdersLTMetPeriodToDate] ),
                Table[TotalOrderUnitsPeriodToDate]
            )
    ),
    0
)


TotalOrdersLTMetPeriodToDate =
COALESCE (
    IF (
        Table.[IsPeriodToDate] = "Yes"
            && Table.[IsCurrentPeriod] = "Yes",
        Table[MetLeadTime],
        0
    ),
    0
)


TotalOrdersLTMetPreviousPeriodToDate =
COALESCE (
    IF (
        Table[IsPeriodToDate] = "Yes"
            && Table[IsPreviousPeriod] = "Yes",
        Table[MetLeadTime],
        0
    ),
    0
)

 

If we are talking about measure then this needs to be calculated in a different way.

 

Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.