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
lbudack
Advocate III
Advocate III

SQL Statement to DAX - JOIN & CASE

Is there a way to write this in DAX? I thought I knew DAX better than SQL, but I guess not. I've been all over these forums looking for solutions, but I can't get it to work the way it does in SQL. 

 

 

SELECT DISTINCT Organization.OrgName,
CASE 
	 WHEN ProjectNumber IS NOT NULL THEN 'Yes' ELSE 'No'
	 END AS Prospect
FROM Project
     RIGHT OUTER JOIN Organization ON Project.ClientOrgID = Organization.OrgID

 

 

Thanks in advance, DAX superstars!  

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @lbudack ,

 

Create a calculated column like so:

Prospect? = 
IF (
    SUMX (
        'Project Table',
        FIND ( 'Org Table'[OrgID], 'Project Table'[OrgID],, 0 )
    ) > 0,
    1
)

 

 

Best regards

Icey

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

View solution in original post

3 REPLIES 3
lbudack
Advocate III
Advocate III

Thanks, @TomMartens! I ended up getting a solution that doesn't involve doing a join or referencing a separate table. Your expression works, but it doesn't quite get me the answer I need since all rows show up as "Yes". 

 

However, in case I come across this situation again, here's more info. 

 

I needed to mark organizations who are or are not prospects by determining if they've ever been used on a project record. 

 

Org Table:

OrgIDOrganizationNameProspect?
1Company ABC 
2Consultant ABC 
3Company XYZ 

 

Project Table:

ProjectNumProjectNameOrgIDOrganizationName
123Project A1Company ABC
324Project B5Company JKL
568Project C2Consultant ABC

 

Icey
Community Support
Community Support

Hi @lbudack ,

 

Create a calculated column like so:

Prospect? = 
IF (
    SUMX (
        'Project Table',
        FIND ( 'Org Table'[OrgID], 'Project Table'[OrgID],, 0 )
    ) > 0,
    1
)

 

 

Best regards

Icey

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

TomMartens
Super User
Super User

Hey @lbudack ,

 

the answer is a little more complex than "Of course you can!" 🙂

But before I try this, here is a link that provides an introduction into Power BI data models, it's important to always be aware that the data model is king. The link

Now my attempt to answer your question, there is an underlying assumption. Your data model contains two tables both are related by a common field: OrgID

The table is on the one side of the relationship and project on the many side of the relationship.

 

Now you can create a calculated column in your project table like so:

 

Prospect =
IF( NOT( ISBLANK( 'Project'[ProjectNumber ) )
, "Yes"
, "No"
)

 

 
From my impression, the right outer join does not matter for the DAX calculated column. Basically there are tables, basically there are no views. Tables are related by ONE column.

 

Hopefully, this helps to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.