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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Get Last state from distinct users by date

I have a sessions details in my dataset that look like this:

SessionDate UserResult
401-04-21 AOK
301-03-21 AFAIL
201-02-21 BFAIL
101-01-21 CRETRY
001-01-21 BOK


I would like to have an additional column that each row contains the value of the last result for the last session for a distinct user, such as:

SessionDate UserResultLast Result
401-04-21 AOKOK
301-03-21 AFAILOK
201-02-21 BFAILFAIL
101-01-21 CRETRYRETRY
001-01-21 B OKFAIL



I have tried to find simple ways by creating new columns and measures, but since the value of user vary, I think it can be a bit more complicated. 

Is there a simple way to achieve this result?

Thanks in advance!

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

Hi, @Anonymous 

Try  calculated column

Expected result =
VAR last_sessionn =
    CALCULATE (
        MIN ( 'Table'[Session] ),
        FILTER (
            'Table',
            'Table'[User] = EARLIER ( 'Table'[User] )
                && 'Table'[Session] > EARLIER ( 'Table'[Session] )
        )
    )
RETURN
    IF (
        ISBLANK ( last_sessionn ),
        'Table'[Result],
        CALCULATE ( MAX ( 'Table'[Result] ), 'Table', 'Table'[Session] = last_sessionn )
    )

119.png

 

or measure :

Expected result2 =
VAR last_session =
    CALCULATE (
        MIN ( 'Table'[Session] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[User] ),
            'Table'[Session] > MAX ( 'Table'[Session] )
        )
    )
RETURN
    IF (
        ISBLANK ( last_session ),
        MAX ( 'Table'[Result] ),
        CALCULATE (
            MAX ( 'Table'[Result] ),
            ALL ( 'Table' ),
            'Table'[Session] = last_session
        )
    )

Please check my pbix file for more details.

 

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Try  calculated column

Expected result =
VAR last_sessionn =
    CALCULATE (
        MIN ( 'Table'[Session] ),
        FILTER (
            'Table',
            'Table'[User] = EARLIER ( 'Table'[User] )
                && 'Table'[Session] > EARLIER ( 'Table'[Session] )
        )
    )
RETURN
    IF (
        ISBLANK ( last_sessionn ),
        'Table'[Result],
        CALCULATE ( MAX ( 'Table'[Result] ), 'Table', 'Table'[Session] = last_sessionn )
    )

119.png

 

or measure :

Expected result2 =
VAR last_session =
    CALCULATE (
        MIN ( 'Table'[Session] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[User] ),
            'Table'[Session] > MAX ( 'Table'[Session] )
        )
    )
RETURN
    IF (
        ISBLANK ( last_session ),
        MAX ( 'Table'[Result] ),
        CALCULATE (
            MAX ( 'Table'[Result] ),
            ALL ( 'Table' ),
            'Table'[Session] = last_session
        )
    )

Please check my pbix file for more details.

 

Best Regards,
Community Support Team _ Eason

Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=LOOKUPVALUE(Data[Result],Data[User],Data[User],Data[Date],CALCULATE(MAX(Data[Date]),FILTER(Data,Data[User]=EARLIER(Data[User]))))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Tahreem24
Super User
Super User

@Anonymous try this:.

 

=CALCULATE (MAX(Table[Result]), FILTER(Table, Table[Date]=MAX(Table[Date])), ALLEXCEPT(Table, Table[User])) 

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
Anonymous
Not applicable

Thanks for your reply, but it does not work since I'm getting the same value for the whole column for your suggestion, independently on the user

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.