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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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