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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Latest Record Based on Date Slicer

First time question poster here!

 

Excel and PowerBi files here: https://www.dropbox.com/sh/g3pfws2xzkmqgqy/AADUrdKWRzHDSCQ5qF8gVQxDa?dl=0 


I have change log of many aspects for employees, and I want to be able to see totals based on the max value of a date slicer.

 

To better explain, I was able to do this in excel with some logic and an array formula.

I have a log of changes for employees, simplified example to only show 1 Attribute. Each row is a new record with a specific date, and is a new Attribute from that point until the next record for that employee.

Record Log.PNG

In a cell, I can specify a date I want to look at, and with logic I know which records are true, or "In View."

In View.PNG

I then have an array formula that will tell me for each employee what record in view is the latest.

Latest Index In View.PNG

And then in a separate table where I have the list of employees, and I look up the latest index in view for each and then lookup the attributes on that index.

VLookups.PNG

It is then trivial to count up totals for all the attributes and see those totals change as I change the Date that I am looking at.

 

Methods attempted in PowerBI:

Loading data to PowerBI keeping only ID, Record Date, and Attribute and create a generated Index in the Query Editor.

PowerBI Record Log.PNG

 

I have set up measures that check the record date against the date slicer,

In View = IF( MAX('Log'[Record Date])<=MAX(DateKey[Date])&&MAX('Log'[Record Date])>=MIN(DateKey[Date]) ,1,0)

 

Return the max index for each employee,

Max Index = MAXX(VALUES('Log'), IF([In View]=1,'Log'[Index],0))

 

And then lookup the attribute.

Latest Attribute = LOOKUPVALUE('Log'[Attribute],'Log'[Index],[Max Index]) 

PowerBI Dashboad.PNGPowerBI Dashboard 2.PNG

As I adjust my date slicer, I can see these attribute and max index changing properly. However, if I check attribute 1 in another slicer, it will return 1 for all 5 employees as all 5 employees have a record with the attribute 1 somewhere in the table.

What i would like to see as the result by slicing 1 is Employee ID 1, 2, and 4 only.

I suspect the order of operations is wrong. This slicer and other measures, counters, etc are filtering down the table and then the measure is finding the latest record of that new context. This is messing up counts and all further use of the model.

I need the latest record against the date slicer regardless of other contexts that happen.

I have attempted to reorder the filtering by using variables, setting up a virtual table with CALCULATETABLE, and I am having major trouble with the syntax.

 

Much thanks for the help!

1 ACCEPTED SOLUTION

Hi @Anonymous 

Check if it is correct on your side.

Create a new table

attribute = VALUES('Log'[Attribute])

Modify measure as below

attribute selected =
VAR maxdate =
    CALCULATE (
        MAX ( 'Log'[Record Date] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[In View] = 1
        )
    )
VAR attr =
    CALCULATE (
        MAX ( 'Log'[Attribute] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[Record Date] = maxdate
        )
    )
RETURN
    IF (
        HASONEFILTER ( attribute[Attribute] ),
        IF (
            SELECTEDVALUE ( attribute[Attribute] ) = attr,
            attr
        ),
        attr
    )

Capture4.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

9 REPLIES 9
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measures

last index in view =
VAR maxdate =
    CALCULATE (
        MAX ( 'Table'[Record Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Employee ID]
                = MAX ( 'Table'[Employee ID] )
                && 'Table'[In View]
                    = TRUE ()
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Employee ID]
                = MAX ( 'Table'[Employee ID] )
                && 'Table'[Record Date] = maxdate
        )
    )


attribute selected =
VAR maxdate =
    CALCULATE (
        MAX ( 'Table'[Record Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Employee ID]
                = MAX ( 'Table'[Employee ID] )
                && 'Table'[In View]
                    = TRUE ()
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[Attribute] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Employee ID]
                = MAX ( 'Table'[Employee ID] )
                && 'Table'[Record Date] = maxdate
        )
    )

Capture14.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hi Maggie,

Thanks for the response!

I have tried the solution but am getting the following error:

 

Error Message:
MdxScript(Model) (24, 20) Calculation error in measure 'Log'[last index in view]: DAX comparison operations do not support comparing values of type Integer with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values.

 

I have uploaded the excel file and the powerbi file to a dropbox link at the top of my post if you want to give it another try. Thanks again!

Hi @Anonymous 

Check the pbix file.

Capture2.JPG

last index in view = 
VAR maxdate =
    CALCULATE (
        MAX ('Log'[Record Date] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[In View]
                    = 1
        )
    )
RETURN
    CALCULATE (
        MAX ('Log'[Index] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ('Log'[Employee ID] )
                && 'Log'[Record Date] = maxdate
        )
    )

attribute selected = 
VAR maxdate =
    CALCULATE (
        MAX ( 'Log'[Record Date] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[In View]
                    = 1
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Log'[Attribute] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[Record Date] = maxdate
        )
    )

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hey Maggie,

Thanks again for attempting again and correcting the syntax. I am however getting the same results as my measure. Screenshots are below. The issue is that when applying a slicer for attribute 1, it is returning all the employees that at one point have had a 1 in the table, not just the employees that have a 1 on the date selected in the slicer.

PowerBI Dashboard 3.PNG

PowerBI Dashboard 4.PNG

Hi @Anonymous 

Check if it is correct on your side.

Create a new table

attribute = VALUES('Log'[Attribute])

Modify measure as below

attribute selected =
VAR maxdate =
    CALCULATE (
        MAX ( 'Log'[Record Date] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[In View] = 1
        )
    )
VAR attr =
    CALCULATE (
        MAX ( 'Log'[Attribute] ),
        FILTER (
            ALLSELECTED ( 'Log' ),
            'Log'[Employee ID]
                = MAX ( 'Log'[Employee ID] )
                && 'Log'[Record Date] = maxdate
        )
    )
RETURN
    IF (
        HASONEFILTER ( attribute[Attribute] ),
        IF (
            SELECTEDVALUE ( attribute[Attribute] ) = attr,
            attr
        ),
        attr
    )

Capture4.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Did not get it completely

But try like

Max Index = CALCULATE(max('Log'[Atribute]),filter('Date','Date'[Date]=max('Date'[Date])))
OR
Max Index = CALCULATE(max('Log'[Atribute]),filter('Date','Date'[Date]=lastdate('Date'[Date])))
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

image.png@amitchandak  In this final table that is obtained after applying the date slicer, when we select Attribute 1 in the slicer, the table should show Employee ID 1, 2 and 4. I think this is the desired end goal.

 

 

 

 

Greg_Deckler
Community Champion
Community Champion

Sample data as text would be extremely helpful. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg, I encountered the table paste error in trying to edit my original post so here is the sample data table:

 

IndexEmployee IDRecord DateAttribute
10000000013/1/20201
20000000013/31/20202
30000000014/5/20201
40000000023/1/20202
50000000023/31/20201
60000000033/15/20201
70000000033/31/20203
80000000043/15/20201
90000000044/15/20203
100000000053/1/20201
110000000054/1/20202

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors