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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Convert DAX Expressions to SQL

I'm a little new to DAX and have a problem!

 

I've been tasked with converting several existing DAX expressions to SQL Server, due to the fact that there are external customers who do not have access to our existing Power BI resources. 

I've managed to convert all of the expessions, except for two. These are:

 

Completed Revenue Flight Controllable D0 Success =

    CALCULATE(SUM('FlightSchedulePerformanceDetail'[Controllable D0])

                ,FILTER('FlightSchedulePerformanceDetail'

                        ,'FlightSchedulePerformanceDetail'[Accountable Flight] = 1 &&

                        'FlightSchedulePerformanceDetail'[Is In] = 1))

 

Controllable D0 =

IF('FlightSchedulePerformanceDetail'[Is Out] = 0,0,IF(AND('FlightSchedulePerformanceDetail'[Total Departure Delay Minutes]>0,

('FlightSchedulePerformanceDetail'[Dept Delay 1 Controllable]+

'FlightSchedulePerformanceDetail'[Dept Delay 2 Controllable]+

'FlightSchedulePerformanceDetail'[Dept Delay 3 Controllable]+

'FlightSchedulePerformanceDetail'[Dept Delay 4 Controllable])>1),0,1))

 

If someone could provide some insight into these, that would be fantastic!

 

Thank you!

3 REPLIES 3
vivran22
Community Champion
Community Champion

Hello @Anonymous 

 

You may try following:

 

For Completed Revenue Flight Controllable D0 Success


SELECT SUM([Controllable D0])
FROM 'FlightSchedulePerformanceDetail'
 WHERE 'FlightSchedulePerformanceDetail'[Accountable Flight] = 1 
 AND 'FlightSchedulePerformanceDetail'[Is In] = 1

For Controllable D0 

CASE WHEN 'FlightSchedulePerformanceDetail'[Is Out] = 0 THEN 0
    WHEN 'FlightSchedulePerformanceDetail'[Total Departure Delay Minutes] > 0 AND 
	('FlightSchedulePerformanceDetail'[Dept Delay 1 Controllable] + 
	'FlightSchedulePerformanceDetail'[Dept Delay 2 Controllable] + 
	'FlightSchedulePerformanceDetail'[Dept Delay 3 Controllable] + 
	'FlightSchedulePerformanceDetail'[Dept Delay 4 Controllable] ) > 1
        ) THEN 0
        ELSE 1
   END

 

You might have to tweak it, but I am hopeful it will give you some direction.

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂 (Hit the thumbs up button!)
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)


https://www.vivran.in/

Connect on LinkedIn

Anonymous
Not applicable

Thank  you! This does the trick...almost!

 

For the Controllable D0 field, I actually need to wrap the entire thing into a SUM. I've been trying and can't quite get it just right.

 

Any ideas??

 

 

@Anonymous 

 

Ideally this should do the trick:

SELECT 
SUM(
CASE WHEN 'FlightSchedulePerformanceDetail'[Is Out] = 0 THEN 0
    WHEN 'FlightSchedulePerformanceDetail'[Total Departure Delay Minutes] > 0 AND 
	('FlightSchedulePerformanceDetail'[Dept Delay 1 Controllable] + 
	'FlightSchedulePerformanceDetail'[Dept Delay 2 Controllable] + 
	'FlightSchedulePerformanceDetail'[Dept Delay 3 Controllable] + 
	'FlightSchedulePerformanceDetail'[Dept Delay 4 Controllable] ) > 1
        ) THEN 0
        ELSE 1
   END
) as SumTotal

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂 (Hit the thumbs up button!)
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)


https://www.vivran.in/

Connect on LinkedIn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.