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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
JRoj
Frequent Visitor

Calculating Latest Status Before a Selected Date

Hello everyone,

 

I’m currently working with an audit table that tracks the implementation statuses of various solutions across different plants and divisions, along with the timestamps for when each status was set.

 

I have recently implemented a "Before" slicer to allow users to filter the data based on a selected date. In my use case, I want to filter the table by some measure lets say IsMostRecent to display only the latest status change prior to the selected date. This way, the table would show only one row for each combination of solution, plant, and division — the most recent one before the selected date.

 

I add below the screenshot of what I want to achieve -> only the green rows are visible in the table, as these are the latest entries prior to the selected filter date grouped by division, solution and plant.

 

divisionplantsolution_idstatusTimestampisMostRecent
PS8dd5db1f92ba1b9cPlanned19-06-24 10:471
PS8dd5db1f92ba1b9cIn use06-05-24 2:060
PS8dd5db1f92ba1b9cIn use06-05-24 2:060
PS8dd5db1f92ba1b9cNo status06-05-24 2:050
PS8dd5db1f92ba1b9cIn use06-05-24 2:030
PS8dd5db1f92ba1b9cPlanned06-05-24 2:020
PS8dd5db1f92ba1b9cPlanned06-05-24 2:020
PS8dd5db1f92ba1b9cIn use06-02-24 12:410
PS8dd5db1f92ba1b9cPlanned01-07-22 11:540
PS8dd5db1f92ba1b9cPlanned28-03-22 11:520
PS8dd5db1f92ba1b9cNo status11-08-21 10:560
PS8dd5db1f92ba1b9cPlanned11-08-21 10:560
PS8dd5db1f92ba1b9cNo status27-04-21 13:190
ME8dd51232192ba1b9cNo status06-02-24 12:411
ME8dd51232192ba1b9cPlanned01-07-22 11:540
ME8dd51232192ba1b9cNo status28-03-22 11:520

sample_picture.png

1 ACCEPTED SOLUTION
v-yajiewan-msft
Community Support
Community Support

Hi @JRoj , dharmendars007, thank you for your prompt reply!

 

  • Create the measure as shown below:
IsMostRecentMeasure = 
VAR SelectedDate = MAX('Date'[Date]) 
VAR CurrentPlant = SELECTEDVALUE('AuditTable'[plant])
VAR CurrentSolution = SELECTEDVALUE('AuditTable'[solution_id])
VAR CurrentDivision = SELECTEDVALUE('AuditTable'[division])

VAR LatestTimestamp = 
    CALCULATE(
        MAX('AuditTable'[Timestamp]),
        FILTER(
            ALL('AuditTable'),
            'AuditTable'[Timestamp] < SelectedDate &&
            'AuditTable'[plant] = CurrentPlant &&
            'AuditTable'[solution_id] = CurrentSolution &&
            'AuditTable'[division] = CurrentDivision
        )
    )

RETURN
IF(
    SELECTEDVALUE('AuditTable'[Timestamp] )= LatestTimestamp,
    1,  
    0   
)
  • Then filter the table visual as shown below:

vyajiewanmsft_0-1727336944493.png

 

Result for your reference:

vyajiewanmsft_1-1727336995575.png

Best regards,

Joyce

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

6 REPLIES 6
v-yajiewan-msft
Community Support
Community Support

Hi @JRoj , dharmendars007, thank you for your prompt reply!

 

  • Create the measure as shown below:
IsMostRecentMeasure = 
VAR SelectedDate = MAX('Date'[Date]) 
VAR CurrentPlant = SELECTEDVALUE('AuditTable'[plant])
VAR CurrentSolution = SELECTEDVALUE('AuditTable'[solution_id])
VAR CurrentDivision = SELECTEDVALUE('AuditTable'[division])

VAR LatestTimestamp = 
    CALCULATE(
        MAX('AuditTable'[Timestamp]),
        FILTER(
            ALL('AuditTable'),
            'AuditTable'[Timestamp] < SelectedDate &&
            'AuditTable'[plant] = CurrentPlant &&
            'AuditTable'[solution_id] = CurrentSolution &&
            'AuditTable'[division] = CurrentDivision
        )
    )

RETURN
IF(
    SELECTEDVALUE('AuditTable'[Timestamp] )= LatestTimestamp,
    1,  
    0   
)
  • Then filter the table visual as shown below:

vyajiewanmsft_0-1727336944493.png

 

Result for your reference:

vyajiewanmsft_1-1727336995575.png

Best regards,

Joyce

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

Thanks @v-yajiewan-msft, this works really fine. I have one more querstion, as I have also other visuals such as Gauge chart, and I would like to filter the whole page by this measure, so the Gauge is also affected by that filter and take only latest values? Is that even possible? I am trying to do something like this:

 

SumOfCoverageForMostRecentStatus = 
CALCULATE(
    SUM('AuditTable'[coverage]),
    FILTER(
        'AuditTable',
        [IsMostRecentStatus] = 1
    )
)

 

Hi @JRoj,

 

Thank you for your feedback.

 

As far as I know, measure can not be used in page filter, and we suggest you add the measure to any visuals you want to filter.

 

Hi @v-yajiewan-msft.


Yes indeed measure can not be used neither in the page filter, nor in the other measure. But I propagated the whole logic of IsMostRecentMeasure to the other measures and it works.

 

Thank you very much!

dharmendars007
Memorable Member
Memorable Member

Hello @JRoj , 

 

Could you please share us the sample data and expected result this will help us to visulize the logic you are mentioning..

 

Thanks, 

Dharmendar S

Added below the original post.

Helpful resources

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