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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
v-rongtiep-msft
Community Support
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] )
    )
)

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
v-rongtiep-msft
Community Support
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] )
    )
)

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

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.