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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
rmbernal
Frequent Visitor

Convert SQL Query to DAX

Hi,

Does anyone know how I would convert this SQL case statement to DAX (see below)?   Any help would be very much appreciated

 

select distinct c.[crm_as_Contact] as contactid,
( select b.Otherval from testingAos_File b ,dim_person p where b.crm_as_Contact=p.ContactId and b.Level_of_Expertise ='Primary Expertise' and b.crm_as_Contact=c.crm_as_Contact ) as Prim_exp,
( select b.Otherval from testingAos_File b ,dim_person p where b.crm_as_Contact=p.ContactId and b.Level_of_Expertise ='Intermediate Expertise' and b.crm_as_Contact=c.crm_as_Contact ) as Interm_exp,
( select b.Otherval from testingAos_File b ,dim_person p where b.crm_as_Contact=p.ContactId and b.Level_of_Expertise ='Advanced Expertise' and b.crm_as_Contact=c.crm_as_Contact ) as Adv_exp
from testingAos_File c
where c.crm_as_Contact in (select contactid from Dim_Person)

 

Further details here:

 

I have 1 Power Bi report, using a data model, I have person table and this calculated table as source:

Calculated table:

rmbernal_0-1711652993084.png

I have more than one record by contact ID on the calculated table above.

 

Here example of my Person table:

rmbernal_1-1711653268558.png

Here I need: I'm expecting to see only 1 record by contact ID using level expertise as column for each one (Primary, Intermediate and Advanced) 

 

Translating my sql query to DAX for creating a new table, here I'm expecting to see on that new table:

rmbernal_2-1711654515169.png

 

Since relationship with Person table would be one to one, I could add columns of Prim_exp, interm_exp and Adv_exp only joining by contact ID what is my businness need.

 

I hope this help better to explain what I'm looking for. Any help of you would be gretly appretiated

 

Thanks!

5 REPLIES 5
lbendlin
Super User
Super User

Sounds like you can do this entirely in the UI, via the matrix visual. 

 

1:1  relationships are usually an indication that tables can be combined into one.

Hi @lbendlinm, I don't know how  to do that you are suggesting..matrix visual? I don't have yet the 1:1 relationship, that's I'm pretending converting the Sql query to a Dax and put the result into a Calculated table.

For now, only I have is this table:

rmbernal_0-1712025173196.png

This is not a 1:1 reationship, because I have 2 or more records by each Contact ID, I need only one record by each contact ID.  Could I do that just using matrix visual?  Could you please explain me further how to do that? I'm not super expert on Power Bi, so I'm trying to solve it, but any possible solution so far.

 

Further details about your solution with Matrix visual based in my screeshot examples above would be greatly appreciated.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

rmbernal
Frequent Visitor

@lbendlin please see my updated post abocve, I already added further information as you suggested. Thanks

lbendlin
Super User
Super User

- Forget SQL

- Describe your business problem

- Provide sample data

- indicate the expected outcome based on the sample data.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors