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
req77
Helper I
Helper I

Count most recent rows only

Hi!
I have a table with this structure:

CODZ     LEVEL     DATE
X  A111  14/03/2023
X  A222  13/03/2023
Z  A444  14/03/2023
Y  A777  14/03/2023
Y  A333  13/03/2023
Y  A777  12/03/2023


I want to create a measure that counts only the number of rows with the most recent date based on the date filter that the user makes in the dashboard.

 

For example:

  • if the user does not filter the dashboard, the measure must show the number of rows from the most recent date in the table (14/03/2023). The measure should bring the value: 3
  • if the user only selects the day 13/03/2023 in the dashboard date filter, this measure should bring the value: 2

How can I do a measure like that?

1 ACCEPTED SOLUTION
ichavarria
Solution Specialist
Solution Specialist

Hi @req77,

 

You can create a measure that calculates the maximum date based on the current filter context and then counts the number of rows that match that maximum date. Here's an example measure that should work for your table:

MaxDateCount =
VAR MaxDate = MAX('Table'[DATE])
RETURN
COUNTROWS(
FILTER('Table', 'Table'[DATE] = MaxDate)
)

 

This measure first uses the MAX function to calculate the maximum date based on the current filter context. It then uses the FILTER function to count the number of rows in the table where the date column matches the maximum date.

 

To use this measure, add it to your visual and make sure that the date column is included in the visual as well. The measure should automatically update based on any date filters that are applied.

 

 

Best regards, 

Isaac Chavarria

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

View solution in original post

1 REPLY 1
ichavarria
Solution Specialist
Solution Specialist

Hi @req77,

 

You can create a measure that calculates the maximum date based on the current filter context and then counts the number of rows that match that maximum date. Here's an example measure that should work for your table:

MaxDateCount =
VAR MaxDate = MAX('Table'[DATE])
RETURN
COUNTROWS(
FILTER('Table', 'Table'[DATE] = MaxDate)
)

 

This measure first uses the MAX function to calculate the maximum date based on the current filter context. It then uses the FILTER function to count the number of rows in the table where the date column matches the maximum date.

 

To use this measure, add it to your visual and make sure that the date column is included in the visual as well. The measure should automatically update based on any date filters that are applied.

 

 

Best regards, 

Isaac Chavarria

If this post helps, then please consider Accepting it as the solution and giving Kudos 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.