cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SFeldmann
Frequent Visitor

Filtering the last valid record dynamically

Hello,

 

I have a the following use case:

 

On the one hand I have employees, where the working hours per week changing from a specific starting date.

On the other hand I have a table, where all changes are posted for each employee with starting date and working hours week.

In my report, I have two single slicers, one for the year ie. 2019, 2020 etc. and one for the months 1 - 12

My challenge now is calculating the active value for working hours per week depending on the Date Filter of the slicers.

Table Employee

2019-08-09_11h55_19.png

 

Table Workscheme

2019-08-09_11h56_46.png

 

What would I expect?

Example 1:

Date Filter (of slicer): February 2019

2019-08-09_12h01_21.png

 

2019-08-09_12h01_53.png

 

Example 2:

Date Filter (of slicer): May 2019

2019-08-09_12h06_38.png

 

2019-08-09_12h06_58.png

 

I tried several approaches with LASTNONBLANK, LASTDATE etc., but none of them worked properly.

Does anybody have an idea how to handle this issue?

 

Thank you in advance 🙂

Stefan

 

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

Hi @SFeldmann ,

 

Firstly, you need to create a new table to save date.

Date =
CALENDAR ( MIN ( 'Table'[Starting Date] ), MAX ( 'Table'[Starting Date] ) )

Then create a column to be compared with Starting date.

YM =
VALUE ( 'Date'[Date].[Year] & FORMAT ( 'Date'[Date], "mm" ) )

Now, you can create a new measure “Hours Week”.

Hours Week =
VAR selectDate =
    SELECTEDVALUE ( 'Date'[YM], MIN ( 'Date'[YM] ) )
RETURN
    CALCULATE (
        SELECTEDVALUE ( 'Table'[Working Hours Week] ),
        FILTER (
            'Table',
            VALUE ( FORMAT ( 'Table'[Starting Date], "yyyymm" ) )
                = VALUE (
                    FORMAT (
                        CALCULATE (
                            MAX ( 'Table'[Starting Date] ),
                            ALLEXCEPT ( 'Table', 'Table'[Employee Code] ),
                            selectDate >= VALUE ( FORMAT ( 'Table'[Starting Date], "yyyymm" ) )
                        ),
                        "yyyymm"
                    )
                )
        )
    )

At last, you can use slicer to filter your table.4-1.PNG

 

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @SFeldmann ,

 

Firstly, you need to create a new table to save date.

Date =
CALENDAR ( MIN ( 'Table'[Starting Date] ), MAX ( 'Table'[Starting Date] ) )

Then create a column to be compared with Starting date.

YM =
VALUE ( 'Date'[Date].[Year] & FORMAT ( 'Date'[Date], "mm" ) )

Now, you can create a new measure “Hours Week”.

Hours Week =
VAR selectDate =
    SELECTEDVALUE ( 'Date'[YM], MIN ( 'Date'[YM] ) )
RETURN
    CALCULATE (
        SELECTEDVALUE ( 'Table'[Working Hours Week] ),
        FILTER (
            'Table',
            VALUE ( FORMAT ( 'Table'[Starting Date], "yyyymm" ) )
                = VALUE (
                    FORMAT (
                        CALCULATE (
                            MAX ( 'Table'[Starting Date] ),
                            ALLEXCEPT ( 'Table', 'Table'[Employee Code] ),
                            selectDate >= VALUE ( FORMAT ( 'Table'[Starting Date], "yyyymm" ) )
                        ),
                        "yyyymm"
                    )
                )
        )
    )

At last, you can use slicer to filter your table.4-1.PNG

 

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @v-eachen-msft,

 

Thank you for your solution, that works totally fine. 

 

One final comment that has to be considered to this solution: They must be no relationship between the Date[Date] and the Workscheme[Starting Date].

 

Best Regards,

Stefan

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

Power BI Dev Camp Session 27

Ted's Dev Camp

This session walks through creating a new Azure AD B2C tenant and configuring it with user flows and custom policies.

Health and Life Sciences Power BI User Group

Health and Life Sciences Power BI User Group

Power BI specialists at Microsoft have created a community user group where customers in the provider, payor, pharma, health solutions, and life science industries can collaborate.