cancel
Showing results 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.

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.

I also have a date slicer:

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).

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
Community Support

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] )
)
)
``````

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.

Community Support

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] )
)
)
``````

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.

Announcements

#### 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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors