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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
AmiraBedh
Super User
Super User

Equivalent of LEFT JOIN subquery containing distinct in DAX

I have the following query : 

 

SELECT d.department
,COUNT(*)
FROM fact_table AS f
LEFT JOIN
(SELECT DISTINCT sk_dept, department FROM dim_department ) AS d ON d.sk_dept=f.fk_dept
WHERE  f.employee_status <> 2
GROUP BY  d.department

This is the output of the query :

Department Count

1                  250

2                  300

 

The department dimension is like below :

DepartmentSK DepartmentId SubDepartment

1                      1                      23

2                      1                      67

3                      1                      120

4                      2                      44

 

The Dept has sub department my measure is showing me duplicates :

 

Employee Count By Dept =
CALCULATE (
DISTINCTCOUNT( fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
How can we include the LEFT JOIN subquery containing distinct in the DAX measure?
 
The output I get with the DAX formula :

Department Count

1                  500

2                  600

The count is duplicated because the deptid is existing many times since each department has many sub departments.


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
1 ACCEPTED SOLUTION
amirabedhiafi
Impactful Individual
Impactful Individual

Try to SUMX with the DISTINCT to get the unique values of the department :

Employee Count By Dept  = 
SUMX (
DISTINCT(VALUES(dim_department[department])),
CALCULATE (
DISTINCTCOUNT(fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
)
)
Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

View solution in original post

3 REPLIES 3
amirabedhiafi
Impactful Individual
Impactful Individual

Try to SUMX with the DISTINCT to get the unique values of the department :

Employee Count By Dept  = 
SUMX (
DISTINCT(VALUES(dim_department[department])),
CALCULATE (
DISTINCTCOUNT(fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
)
)
Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
parry2k
Super User
Super User

@AmiraBedh it will be easier if you provide sample data and the expected output. 

 

Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I updated the question.


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors