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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
LaelTejo
Frequent Visitor

DISTINCTCOUNT with Condition, filtered based on latest update

Hello. I have created a report for Project Progress Update.

 

One of the highlight is the # of Project Completed, # of Project On Progress, and # of Project Not Started.

 

Considering on their importance, I am making an individual card visualization for each. I use the following DAX for January report:

# of On Progress = CALCULATE(DISTINCTCOUNT(Table1[Project Name]), Table1[Project Status] IN {On Progress})

 

It works when the data only contains the information for January. The data, however, is separated into months and is appended every 25th. Therefore, it would inflate the number for each status.

 

I want it to only count the LATEST Update for that project. Imagine the data look like this:

Reporting DateProject NameProject Status
25-Jan-24Project AOn Progress
25-Jan-24Project BNot Started
25-Jan-24Project COn Progress
25-Jan-24Project DCompleted
25-Feb-24Project ACompleted
25-Feb-24Project BNot Started
25-Feb-24Project COn Progress
25-Feb-24Project EOn Progress
25-Mar-24Project BOn Progress
25-Mar-24Project COn Progress
25-Mar-24Project ECompleted
25-Mar-24Project FNot Started
25-Mar-24Project GOn Progress

 

Project D is completed on Jan, so it does not show up any other time, and I can use the usual DAX for Completed. The other ones, however, still reports changed. I want Project B to be calculated on the "On Progress" card and not on the "Not Started" card.

 

If I were to open the report after 25 March, the data will show 3 On Progress, 3 Completed, and 1 Not Started.

 

Please help me create the measure to support this. I have scoured this forum, and am unable to find the exact method to calculate with DISTINCTCOUNT. If possible, I would like to avoid needing to add a column to the data.

 

Thank you.

1 ACCEPTED SOLUTION
123abc
Community Champion
Community Champion

To achieve the desired result of counting the latest status of each project, you can use the following DAX measure:

 

# of On Progress Latest =
VAR LatestReportingDate =
CALCULATE(
MAX(Table1[Reporting Date]),
ALLEXCEPT(Table1, Table1[Project Name])
)
RETURN
CALCULATE(
DISTINCTCOUNT(Table1[Project Name]),
FILTER(
Table1,
Table1[Project Status] = "On Progress" &&
Table1[Reporting Date] = LatestReportingDate
)
)

 

This measure calculates the distinct count of project names where the project status is "On Progress" and the reporting date matches the latest reporting date for each project.

Here's how the measure works:

  1. VAR LatestReportingDate: This variable calculates the maximum reporting date for each project, removing all filters except the project name. This ensures that we isolate the latest reporting date for each project.

  2. RETURN: This is where the calculation is performed. It calculates the distinct count of project names where the project status is "On Progress" and the reporting date matches the latest reporting date calculated in the first step.

This measure will dynamically adjust to the latest reporting date for each project, ensuring that only the latest status is counted.

 

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

View solution in original post

2 REPLIES 2
123abc
Community Champion
Community Champion

To achieve the desired result of counting the latest status of each project, you can use the following DAX measure:

 

# of On Progress Latest =
VAR LatestReportingDate =
CALCULATE(
MAX(Table1[Reporting Date]),
ALLEXCEPT(Table1, Table1[Project Name])
)
RETURN
CALCULATE(
DISTINCTCOUNT(Table1[Project Name]),
FILTER(
Table1,
Table1[Project Status] = "On Progress" &&
Table1[Reporting Date] = LatestReportingDate
)
)

 

This measure calculates the distinct count of project names where the project status is "On Progress" and the reporting date matches the latest reporting date for each project.

Here's how the measure works:

  1. VAR LatestReportingDate: This variable calculates the maximum reporting date for each project, removing all filters except the project name. This ensures that we isolate the latest reporting date for each project.

  2. RETURN: This is where the calculation is performed. It calculates the distinct count of project names where the project status is "On Progress" and the reporting date matches the latest reporting date calculated in the first step.

This measure will dynamically adjust to the latest reporting date for each project, ensuring that only the latest status is counted.

 

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

It works!

 

Thank you.

 

I am quite new to this, and I did not realize we can make a new VAR in DAX. Thanks for the help!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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