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
Anonymous
Not applicable

Counting distinct items based on date criteria

Greetings, 

 

I am having an issue with figuring out a measure that I just cant seem to hammer out. I am very new with using DAX.

 

I am needing to count rows based on dates, essentially something like: 

 

Measure = CountRows(
              Filter(
                     Table, Table[NextDue].Date <= Today()))

 

However, the table it is counting contains duplicate values such as:

powerbi help.png

 

What I am needing this formula to do is identify the most recent date in the 'NextDue' column for each distinct name in the 'Name' column. 

 

For instance, if there were 5 different names in the 'Name' column each with 3 items that all containt different dates it would identify which date is the latest for that distinct 'Name' and then determine whether it is less than Today(). If it is, it counts that item.

 

I hope this is clear enough, I am not 100% on all the PowerBI jargon. 

 

Thanks for any help!

1 ACCEPTED SOLUTION

Hi @Anonymous 

Thanks for reaching out to us.

 

Try this measure

count = 
COUNTROWS(FILTER('Table','Table'[NextDate] < TODAY() && 'Table'[NextDate] = CALCULATE(MAX('Table'[NextDate]),ALLEXCEPT('Table','Table'[Name]))))

vxiaotang_0-1635384639797.png

vxiaotang_1-1635384807321.png

I also create a sample for your reference, see file attached bellow.

 

 

Best Regards,

Community Support Team _Tang

If this post helps, 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 @Anonymous 

 

I tried to solve the problem based on my understaing. If this is not the requirement, please post more details as @Greg_Deckler mentioned below.

 The below measure will get the count of items which has dates less than today.

 

 

m_count1 = 
    CALCULATE( COUNT(Table1[Client]), 
               FILTER(Table1,Table1[Date]<TODAY()),
               ALLEXCEPT(Table1,Table1[Client])
              )

 

 

 

Here is teh result for the sample dataset:

rajendran_0-1634926023574.png

Thanks
Raj

Greg_Deckler
Super User
Super User

@Anonymous Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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...
Anonymous
Not applicable

Thanks for the response, I will try to provide more context. 

 

So the data is set out in this format:

NameDateNextDate
Staff 17/1/2110/1/21
Staff 110/1/211/1/22
Staff 26/1/219/1/21
Staff 29/1/2112/1/21
Staff 37/1/2110/1/21
Staff 33/1/216/1/21

 

What I am needing to do is find the highest date in the 'NextDate' for each unique name in the 'Name' column. So the formula will identify the following:

 

NameNextDate
Staff 11/1/22
Staff 212/1/21
Staff 36/1/21

 

From there, I need it to identify which of the dates in the 'NextDate' column have already passed and count them to display in a data card. So with the data above, it would put "1" in the data card, since the only 'NextDate' value that has passed is the one for Staff 3. 

 

Thank you, it is greatly appreciated. 

 

Hi @Anonymous 

Thanks for reaching out to us.

 

Try this measure

count = 
COUNTROWS(FILTER('Table','Table'[NextDate] < TODAY() && 'Table'[NextDate] = CALCULATE(MAX('Table'[NextDate]),ALLEXCEPT('Table','Table'[Name]))))

vxiaotang_0-1635384639797.png

vxiaotang_1-1635384807321.png

I also create a sample for your reference, see file attached bellow.

 

 

Best Regards,

Community Support Team _Tang

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

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.