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
blazko
Helper III
Helper III

calculating previous time value

Hi.

I'm having a problem calulating a column with previous record time.

My table is : date, user, time. I need to put nwe column with like one step backward action.

So when a cartain user has activity in time column : 13:10, 13:20, 13:50, i want to have in one row 13:20 and (time), and 13:10 (previous time).

Thanks for the response in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

This should do it:

 

Previous Time =
VAR CurrentTime = Table1[Time]
VAR CurrentUser = Table1[User]
VAR CurrentDate = Table1[Date]
RETURN
    CALCULATE (
        MAX ( Table1[Time] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Time] < CurrentTime
                && Table1[User] = CurrentUser
                && Table1[Date] = CurrentDate
        )
    )

2017-10-20 12_54_34-NBA Sample - Power BI Desktop.png

 

Note that the column will show a blank value if it is the first time for a given date.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

This should do it:

 

Previous Time =
VAR CurrentTime = Table1[Time]
VAR CurrentUser = Table1[User]
VAR CurrentDate = Table1[Date]
RETURN
    CALCULATE (
        MAX ( Table1[Time] ),
        FILTER (
            ALL ( Table1 ),
            Table1[Time] < CurrentTime
                && Table1[User] = CurrentUser
                && Table1[Date] = CurrentDate
        )
    )

2017-10-20 12_54_34-NBA Sample - Power BI Desktop.png

 

Note that the column will show a blank value if it is the first time for a given date.

hi, can I do that in M?

Anonymous
Not applicable

@blazko , you could accomplish this by doing a self join.

 

In Query Editor, merge the table to itself...join on User and Date, left outer join.  Then expand the nested table, and aggregate the time column to MIN.

 

Let me know if you need the exact M code, but this should be feasible solely through the UI.

Thanks 🙂

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.