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
lmh100
New Member

Count distinct values by date

Hi, 

 

I am trying to create a calculated column in a table - based on counted distinct values that appear during the month - an example of the table is below:

 

DateUnique valueCount requried
31/01/2017A12
31/01/2017B21
31/01/2017A12
31/01/2017B31
31/01/2017B41
28/02/2017A12
28/02/2017A12
28/02/2017B22
28/02/2017B22
31/03/2017A11
31/03/2017B22
31/03/2017B22
31/03/2017C31

 

I have tried CALCULATE(DISTINCTCOUNT( UNIQUE VALUE , UNIQUE VALUE = UNIQUE VALUE, CALENDAR[DATE])

 

But i am just returned with the number rows in that month - rather than the count required column

 

Any help would be appreciated

 

Thanks,

 

Laurence

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @lmh100

 

Try this column

 

Count Required =
CALCULATE (
    COUNT ( TableName[Unique value] ),
    FILTER (
        ALLEXCEPT ( TableName, TableName[Unique value] ),
        MONTH ( TableName[Date] ) = MONTH ( EARLIER ( TableName[Date] ) )
    )
)

 

or this one

 

Count Required =
CALCULATE (
    COUNT ( TableName[Unique value] ),
    ALLEXCEPT ( TableName, TableName[Unique value], TableName[Date].[Month] )
)

 


Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

If you just create a Table visualization and drop in your Date column, Unique Value column and then drop in your Date column again and switch the aggregation to Count you will achieve what you are looking for.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Zubair_Muhammad
Community Champion
Community Champion

Hi @lmh100

 

Try this column

 

Count Required =
CALCULATE (
    COUNT ( TableName[Unique value] ),
    FILTER (
        ALLEXCEPT ( TableName, TableName[Unique value] ),
        MONTH ( TableName[Date] ) = MONTH ( EARLIER ( TableName[Date] ) )
    )
)

 

or this one

 

Count Required =
CALCULATE (
    COUNT ( TableName[Unique value] ),
    ALLEXCEPT ( TableName, TableName[Unique value], TableName[Date].[Month] )
)

 


Regards
Zubair

Please try my custom visuals

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.