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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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

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] ) )

 










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


Proud to be a Super User!









"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.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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