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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lnik
Frequent Visitor

Distinct count by max date

Hi everyone,

I am trying to calculate distinct values based on max date column.

 

lnik_0-1719219805202.png

But with measure 

DistinctCount = calculate(DISTINCTCOUNT(Table1[Item]),Table1[Date Visit]=MAX(Table1[Date Visit]))
it count also Item 3 although he is not with max date.
Thank you!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@lnik 

I am glad to help you. 

According to your description, you want to distinct count by max date? 

If I understand you correctly, then you can refer to my solution. 

 

  1. You can start by creating a new table. 

vfenlingmsft_0-1719284504157.png

 

 

Table 2 = 
VAR _distinct =
    SUMMARIZE (
        'Table',
        'Table'[Item],
        'Table'[Customer],
        'Table'[Date Visit],
        "MaxDate",
            CALCULATE (
                MAX ( 'Table'[Date Visit] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Item] = EARLIER ( 'Table'[Item] ) )
            )
    )
RETURN
    FILTER (
        _distinct,
        IF ( 'Table'[Item] = 3, BLANK (), 'Table'[Date Visit] = [MaxDate] )
    )

 

  1. Create a Measure for calculating the number of rows corresponding to each Item, and you'll end up with the result you want. 

vfenlingmsft_1-1719284504165.png

 

DistinctCount = 
VAR _currentItem =
    MAX ( 'Table 2'[Item] )
RETURN
    COUNTROWS ( FILTER ( ALL ( 'Table 2'[Item] ), 'Table 2'[Item] = _currentItem ) )

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
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

4 REPLIES 4
Anonymous
Not applicable

Hi,@lnik 

I am glad to help you. 

According to your description, you want to distinct count by max date? 

If I understand you correctly, then you can refer to my solution. 

 

  1. You can start by creating a new table. 

vfenlingmsft_0-1719284504157.png

 

 

Table 2 = 
VAR _distinct =
    SUMMARIZE (
        'Table',
        'Table'[Item],
        'Table'[Customer],
        'Table'[Date Visit],
        "MaxDate",
            CALCULATE (
                MAX ( 'Table'[Date Visit] ),
                FILTER ( ALL ( 'Table' ), 'Table'[Item] = EARLIER ( 'Table'[Item] ) )
            )
    )
RETURN
    FILTER (
        _distinct,
        IF ( 'Table'[Item] = 3, BLANK (), 'Table'[Date Visit] = [MaxDate] )
    )

 

  1. Create a Measure for calculating the number of rows corresponding to each Item, and you'll end up with the result you want. 

vfenlingmsft_1-1719284504165.png

 

DistinctCount = 
VAR _currentItem =
    MAX ( 'Table 2'[Item] )
RETURN
    COUNTROWS ( FILTER ( ALL ( 'Table 2'[Item] ), 'Table 2'[Item] = _currentItem ) )

 

 

I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Fen Ling,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you, works perfectly!

One more question.

Is it possible if i add slicer for year and month, when selecting a specific month it dynamically to calculate distinct count for the items based on the maximum date for that month?

Anonymous
Not applicable

Hello friend, 
I have tried the same formula you mentioned...its working....sharing the snaps

Rakesh1705_0-1719223755257.png

Please let me know the problem you are facing.

I want to use ut in matrix visualisation but there it shows 1 against item 3 and I expect it to be empty

lnik_1-1719238092358.png

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.