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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
diablo9083
Frequent Visitor

DISTINCTCOUNT Not working as expected in Matrix Visual

I have a matrix visual, and I need to use DISTINCTCOUNT in a calculation for the matrix, but I can't get it to aggregate. If I toss the column into the matrix and put the distinct count aggregation on it, it works fine (Leftmost Days of Charges below). If I make a column Days of Charges = DISTINCTCOUNT(Table[Date]), distinct count doesn't aggregate by department. It just gives me a scalar value. How do I get DISTINCTCOUNT(Table[Date]) to aggregate properly?

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from danextian and SamWiseOwl , please allow me to provide another insight:

Hi, @diablo9083 

Regarding the issue you raised, my solution is as follows:

I share the same idea as SamWiseOwl. If your expected result is to directly use the distinct values of the date column, as shown in the image below:

vlinyulumsft_0-1734328542199.png

Then I suggest you directly create a measure:

vlinyulumsft_1-1734328542199.png

 

Days of Charges = DISTINCTCOUNT('Table'[Date])

 

Here is my sample data:

vlinyulumsft_2-1734328570547.png

The final result is as follows:

vlinyulumsft_3-1734328570548.png

If you wish to create a calculated column, I recommend trying the following calculated column:

vlinyulumsft_4-1734328593193.png

 

Column = CALCULATE(DISTINCTCOUNT('Table'[Date]),ALLEXCEPT('Table','Table'[ChargeID],'Table'[Department]))

 

vlinyulumsft_5-1734328622780.png

However, the total part will still need to be adjusted using a measure:

 

MEASURE =
IF (
    HASONEVALUE ( 'Table'[ChargeID] ),
    MAX ( 'Table'[Column] ),
    DISTINCTCOUNT ( 'Table'[Date] )
)

 

Here's my final result, which I hope meets your requirements.

vlinyulumsft_6-1734328770042.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

View solution in original post

5 REPLIES 5
danextian
Super User
Super User

Hi @diablo9083 

Since the first Days of Charges works fine, I am  assuming you're trying to get the sum of this aggregation at the total level.  If so try,

SUMX ( VALUES ( 'table'[deparment code] ), DISTINCTCOUNT ( 'table'[Date] ) )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
SamWiseOwl
Super User
Super User

Hi @diablo9083 
Calculated columns don't automatically get filtered.
If you create a measure and use DistinctCount(table[column]) then it will automatically filter.

Measures are dynamic and will change based on slicers and other visuals.

 

Should you absolutely require it to be a column use Calculate(DistinctCount(table[column])) but this will NOT be dynamic in your visual.


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

I gave this a shot, and it didn't seem to work either.

Anonymous
Not applicable

Thanks for the reply from danextian and SamWiseOwl , please allow me to provide another insight:

Hi, @diablo9083 

Regarding the issue you raised, my solution is as follows:

I share the same idea as SamWiseOwl. If your expected result is to directly use the distinct values of the date column, as shown in the image below:

vlinyulumsft_0-1734328542199.png

Then I suggest you directly create a measure:

vlinyulumsft_1-1734328542199.png

 

Days of Charges = DISTINCTCOUNT('Table'[Date])

 

Here is my sample data:

vlinyulumsft_2-1734328570547.png

The final result is as follows:

vlinyulumsft_3-1734328570548.png

If you wish to create a calculated column, I recommend trying the following calculated column:

vlinyulumsft_4-1734328593193.png

 

Column = CALCULATE(DISTINCTCOUNT('Table'[Date]),ALLEXCEPT('Table','Table'[ChargeID],'Table'[Department]))

 

vlinyulumsft_5-1734328622780.png

However, the total part will still need to be adjusted using a measure:

 

MEASURE =
IF (
    HASONEVALUE ( 'Table'[ChargeID] ),
    MAX ( 'Table'[Column] ),
    DISTINCTCOUNT ( 'Table'[Date] )
)

 

Here's my final result, which I hope meets your requirements.

vlinyulumsft_6-1734328770042.png

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

Can you provide a sample of the data or mock up some data.


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.