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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
GRT9791
Frequent Visitor

Count rows with the latest date before a given date

Hello, I have a table in my data model like the table shown in the below image.

In my report I have created a slicer to introduce a date and I need to create several measures to count rows with the different status. Measure A =count the rows with status A where Date<=the date selected in the slicer, Measure C =count the rows with status C Date<=the date selected in the slicer, etc. But I have count only one row per group (the row with the lastest date <= the selected date).

For example, if I select 03/04/2023 I need to count only the yellow rows --> The values would be: Measure A=2;  Measure B=0; Measure P=1; Measure R=0

GRT9791_0-1683709952192.png

Thanks a lot

 

2 REPLIES 2
FreemanZ
Super User
Super User

hi @GRT9791 

Not sure if i fully get you, please try to

1) plot a slicer with a calculated table like:

Slicer = ALL(data[Date])

2) plot a table visual with group and status columns and a measure like:

Measure = 
COUNTROWS(
    FILTER(
        data,
        data[Date]<MAX(Slicer[Date])
    )
)+0

it worked like:

FreemanZ_0-1683714499989.png

FreemanZ_2-1683714535785.png

 

FreemanZ_1-1683714518502.png

Thanks a lot but it's not exactly what I need, because I have to count only one row (the row with the lastest date <= the selected date). Finally I managed to do it, doing the next steps:

1. Create a  measure that calculates the lastest date <= the selected date in the slicer

Measure1=

VAR fechamax =
    MAX (Fecha[Date] )
RETURN
    CALCULATE (
        MAX ( TABLA[Date] ),
        FILTER ( ALLEXCEPT('TABLA',TABLA[GROUP] ), TABLA[DATE] <= fechamax )
    )
2. Create an indicator measure:
Measure2=IF([Measure1]=SELECTEDVALUE(TABLA[Date]),1,0)
3. Create the counter measure:
counter=SUMX(TABLA, [Measure2])

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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