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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kkishba2
Helper I
Helper I

In Need of Help to Convert SQL statement to DAX

I am new to Power BI and DAX.  I need assistance converting (learning how to convert) a SQL statement to DAX. The statement below is useful extracting against SSMS, but we have a Semantic Model which pulls in all of the identified tables - and DAX is needed to create the report in PowerBI.

 

Any guidance would be helpful.  Thank you.

 

Select W.Wrk + '-' + RIGHT(WS.Sample,2) as SampleID,
WS.SampleName,
WS.Sampled,
CONVERT(VARCHAR(12), SA.nResult) AS ReportedResult,
SA.Analyte,
CONVERT(VARCHAR(12),
SA.Result) AS InitialResult,
WS.SampledBy,
Case
When ws.sampledby = 'adam aleon'
Then 'AL'
Else sec.initials
End As Initials,
SA.Initials as ReviewedBy,
se.Status
From WRK as W
Inner Join WRKSAMPLE as WS On W.Wrk = WS.Wrk
Inner Join SAMPLEANALYSIS as SA On WS.Sample = SA.Sample And
WS.Wrk = SA.Wrk
Left Join SECURITY as Sec On Sec.Fullname = WS.SampledBy
left join sampleextraction as se on se.wrk = sa.wrk and se.sample = sa.sample and se.analysis = sa.analysis
Where W.ProjectNumber = 'p01072' and WS.Sampled >
--First day of last month
DATEADD(m,DATEDIFF(m,0,GETDATE())-1,0)
And WS.Sampled <
--First day of this month
DATEADD(ms,-2,DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0))
And SA.Initials <> ''
And SA.IsQC = 0
And WS.SampleName Like 'S%'
And WS.SampleName Not Like '%A%'
And WS.SampleName Not Like '%B%'
And WS.SampleName Not Like 'SPV%'
And SE.status <> 'cancelled'
ORDER BY WS.Wrk, WS.Sample, SA.Analyte

1 ACCEPTED SOLUTION

Thats great but unforutanetly at the first sight the SQL query looks to complicated to be converted to DAX .There are 4 tables involved with multiple joins with to many predicates.If its me I would stick to SQL View approach.

 

But if you still would like to try the DAX way, then post the semantic model,the business rules and the sample data here.



Regards,
Sachin
Check out my Blog

View solution in original post

6 REPLIES 6
kkishba2
Helper I
Helper I

Thank you.  I was hoping to learn how this would translate to DAX - so that I can begin to understand the language and be able to code for myself in the future.

selectdax.in

Thats great but unforutanetly at the first sight the SQL query looks to complicated to be converted to DAX .There are 4 tables involved with multiple joins with to many predicates.If its me I would stick to SQL View approach.

 

But if you still would like to try the DAX way, then post the semantic model,the business rules and the sample data here.



Regards,
Sachin
Check out my Blog
SachinNandanwar
Super User
Super User

Why not just create a SQL view of the above statement and feed that as an input to your semantic model ?



Regards,
Sachin
Check out my Blog

I am very new to this - so I'm not sure what that would look like (adding a view to the semantic model).

SQL View in your database.

https://en.wikipedia.org/wiki/View_(SQL)



Regards,
Sachin
Check out my Blog

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.