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
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
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors