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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Bananathan
Frequent Visitor

Multiple dates per ID - only use closest date to selected date for a measure

Sorry for the title being kinda complex - I will try to explain better here:

I have the following (simplified) dataset. Anytime an employee changes (e.g. promoted or switched department) in their record, a new row is added at the end of the month The most recent row is blank.

Bananathan_5-1678796623581.png

 

I also have a date slicer: 

Bananathan_1-1678796274628.png

 

I have created a calculated column that changes the blank date into the previous date + 1 month. I also have a measure that will give me the closest date for each employee that is less than the selected date, or if there isn't one, it will give me the calculated column date I just mentioned. To show you what I mean: see the 3 images below. The ID 4364 has the following end dates: 31/03/2022/ 31/07/2022 and blank. Therefore when I select June, the first date is the closest, for July the second date is closest and past July it will give my calculated column of the previous date +1 month (essentially the third blank date).

Bananathan_2-1678796445475.png

Bananathan_3-1678796464809.png Bananathan_4-1678796471110.png

 

 

Here is the measure that gives me the closest date: 

Latest Selected Date =
VAR End_of_Month = EOMONTH( SELECTEDVALUE('Date Table'[Date]),0 )
RETURN
CALCULATE (
    MAX ( 'Data'[Previous Date + 1 month] ) ,
    ALLEXCEPT ( 'Data' , 'Data'[Id]) ,
    'Data'[Previous Date + 1 month] <= End_of_Month
)

What I'm trying to do is run a count on ID based on the selected date that will only use the row that matches the above measure's calculated date for each ID. Here is what I've got so far.. but does not work:

CALCULATE(
    COUNT(''[Id]),
    FILTER(
        'Data',
        'Data'[Previous Date + 1 month] = [Latest Selected Date]
    )
)
 
In this measure, I believe my filter for the [Latest Selected End Date] is just the same date as the date in the slicer, it isn't being split per ID, how would I go about doing this?
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Bananathan ,

Please have a try.

calculated date for each ID:

You can add the part:

measure =
CALCULATE (
    COUNT ( ''[Id] ),
    FILTER (
        ALL ( 'Data' ),
        'Data'[Previous Date + 1 month] = [Latest Selected Date]
            && 'data'[id] = SELECTEDVALUE ( 'data'[id] )
    )
)

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

1 REPLY 1
Anonymous
Not applicable

Hi @Bananathan ,

Please have a try.

calculated date for each ID:

You can add the part:

measure =
CALCULATE (
    COUNT ( ''[Id] ),
    FILTER (
        ALL ( 'Data' ),
        'Data'[Previous Date + 1 month] = [Latest Selected Date]
            && 'data'[id] = SELECTEDVALUE ( 'data'[id] )
    )
)

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors