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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.