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
ranjanrkl
New Member

I need help in translating the following SQL to DAX

SQL 1:

CONVERT(VARCHAR(8),CASE WHEN
(SUM(CASE WHEN InResult IN ('I2','I5','I8','I9','I18','I25','I31','I32','I33') AND
FinalFate IN ('Q10','Q24','Q26') AND
DATEDIFF (s, RouteToQTime, AgentAnswerTime) > 0
THEN DATEDIFF(s, RouteToQTime, AgentAnswerTime)
ELSE NULL
END)) IS NULL OR
(SUM(CASE
WHEN InResult IN ('I2','I5','I8','I9','I18','I25','I31','I32','I33') AND
FinalFate IN ('Q10','Q24','Q26')
THEN 1
ELSE NULL
END)) IS NULL
THEN 0
ELSE DATEADD(ss,SUM(CASE WHEN
InResult IN ('I2','I5','I8','I9','I18','I25','I31','I32','I33') AND
FinalFate IN ('Q10','Q24','Q26') AND
DATEDIFF (s, RouteToQTime, AgentAnswerTime) > 0
THEN DATEDIFF(s, RouteToQTime, AgentAnswerTime)
END)/SUM(CASE
WHEN InResult IN ('I2','I5','I8','I9','I18','I25','I31','I32','I33') AND
FinalFate IN ('Q10','Q24','Q26')
THEN 1
END),0)
END,108) AS [RC HoldTime]

SQL 2:
SELECT
CASE WHEN (GROUPING(QueueName)=1)
THEN 'Grand Total'
ELSE QueueName
END AS Queue,

Please note, we are on SQL Server 2016 (SP3) (KB5003279) and IN Operator in DAX is not supported in SQL Server 2016.

Thanks in advance.

1 REPLY 1
Anonymous
Not applicable

Hi @ranjanrkl ,

In order to give you a quicker solution, could you please share the example table data referenced in these two SQL query tables (with sensitive information removed) and the final result you want. Also, please explain the calculation logic in detail.

Also, in the above two SQL statements, the CASE... WHEN statements can be implemented with DAX IF or SWITCH function, and IN can be implemented with DAX IN function. For details, you can check the links below.

Write Conditional Statement Using SWITCH in DAX and Power BI

The IN operator in DAX

 

In addition, you can connect to the SQL Server database in Power BI Desktiop and fill in the two SQL Query in the Advanced opitions below. The only problem is that you will only get one table...

Import data from a database using native database query

yingyinr_2-1655364008111.png

Best Regards

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.