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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
ExcelMonke
Super User
Super User

Distinctcount of Individuals in a Department Not Returning Expected Result

Hello,

I am currently running into an issue where my DistinctCount Measure is not returning the expected result. I am also unable to figure out where it is going wrong, even after diving into it in DAX Studio.
Goal:
Count distinct number of individuals in a department any given week

Current Result (Test Column):

ExcelMonke_0-1709664065053.png

Expected Result:
The expected result should be 2 across the rows


This is my current DAX for the "TEST" Measure:

CALCULATE (
    DISTINCTCOUNT ( NameTable[Name] ),
    ALLEXCEPT ( 'Location Dim', 'Location Dim'[DepartmentName] ),
    ALLEXCEPT('Date Dim','Date Dim'[WeekBeginningDT])
)

Current DAX within Studio:

DEFINE
MEASURE 'Measure Table'[TEST] = CALCULATE (
    DISTINCTCOUNT ( NameTable[Name] ),
    ALLEXCEPT ( 'Location Dim', 'Location Dim'[DepartmentName] ),
    ALLEXCEPT('Date Dim','Date Dim'[WeekBeginningDT])
)
EVALUATE
FILTER(
SUMMARIZECOLUMNS(
    'Date Dim'[WeekBeginningDT],
    'Location Dim'[DepartmentName],
    NameTable[SpecialNames],
    KEEPFILTERS( FILTER( ALL( 'Date Dim'[WeekBeginningDT] ), 'Date Dim'[WeekBeginningDT] >= DATE(2023,12,10) && 'Date Dim'[WeekBeginningDT] <= DATE(2024,2,25) )),
    KEEPFILTERS( TREATAS( {"XXX"}, 'Location Dim'[DepartmentName] )),
    KEEPFILTERS( TREATAS( {"YYY"}, NameTable[YYY] )),
    KEEPFILTERS( TREATAS( {"Y"}, NameTable[SpecialNames] )),
    "Hours", [Hours],
    "TEST", [TEST]
)
,[Hours] > 0
)
ORDER BY 
    'Date Dim'[WeekBeginningDT] ASC,
    'Location Dim'[DepartmentName] ASC,
    NameTable[SpecialNames] ASC

I added in the filters to see if this was a filter issue. The filters listed in the DAX Studio code are the same as my page level filters in the PBI Desktop

Regardless of whether the measure is built in DAX Studio or within PBI Desktop Directly, I keep getting a result that is not expected.

Any help is appreciated!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@ExcelMonke , what is expected output, the below will ignore all filter other than Department and WeekBegining date

 

CALCULATE (
DISTINCTCOUNT ( NameTable[Name] ),
ALLEXCEPT ( 'NameTable', 'Location Dim'[DepartmentName] ,'Date Dim'[WeekBeginningDT])
)

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
ExcelMonke
Super User
Super User

thank you for the response. The expected value should just be 2, rather than 4578, because during this time period there are only 2 individuals in that department.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

Hi @amitchandak ,thanks for the quick reply, you are correct, and I add to the list of possible causes.

Hi @ExcelMonke ,

Regarding your question, there are three tables in total.
Fact table: NameTable
Dimension table: Location Dim , Date Dim

1. I've assumed some data :

vzhouwenmsft_0-1710750831081.png

vzhouwenmsft_1-1710750896443.png

vzhouwenmsft_2-1710750905559.png

2. Ensure that there is an active one-to-many relationship between the fact table and the dimension table. Incorrect model relationships will affect the delivery of filters, details of which can be found below:

Model relationships in Power BI Desktop - Power BI | Microsoft Learn

3. The problem may be with your original dax expression. Modify your dax expression as amitchandak provides:

 

Measure = CALCULATE(DISTINCTCOUNT(NameTable[Name]),ALLEXCEPT('NameTable','Date Dim'[WeekBeginningDT],'Location Dim'[DepartmentName]))

 

4. Final output:

vzhouwenmsft_3-1710751007080.png

vzhouwenmsft_4-1710751014907.png


Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@ExcelMonke , what is expected output, the below will ignore all filter other than Department and WeekBegining date

 

CALCULATE (
DISTINCTCOUNT ( NameTable[Name] ),
ALLEXCEPT ( 'NameTable', 'Location Dim'[DepartmentName] ,'Date Dim'[WeekBeginningDT])
)

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you for the reply! If the NameTable is not the main fact table, would I have to change the ALLEXCEPT table to the fact table or can I use the NameTable?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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