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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.