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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Opilio2
Frequent Visitor

New column with value of next row grouped/filtered by multiple columns

Hi everyone, 

since I'm no DAX pro, I urgently need your help with the following issue. 

Background: I'm analyzing the use of electronic devices. To be specific, I want to know how often users start different sequential programs in the daily use. That is, if a certain program on device A on day x is started, what is the next program?

Data basically looks like this: 

Device IDTimestampProgram ID
A2022-01-01 14:38   ID1
B2022-01-01 09:12  ID 2
A2022-01-03 19:45   ID 3
C2022-01-04 19:45   ID 2
B2022-01-01 11:03   ID 2
B2022-01-01 22:54   ID 1
A2022-01-03 23:09   ID 1

I need a new column "NextProgramSameDay"  which, for every distinct device and every single day, contains the program ID of the directly following program on the same day:

Device IDTimestampProgramNextProgramSameDayComment (for clarification, not to be included in the dataframe)
A2022-01-01 14:38ID 1 no next program because no additional program was started on the same day in device A
B2022-01-01 09:12ID 2ID 2Next program on device B on same day is program 2 at 11:03
A2022-01-03 19:45ID 3ID 1Next program on device A on  same day is program 1 at 23:09
C2022-01-04 19:45ID 2 no next program because no additional program was started on the same day in device C
B2022-01-01 11:03ID 2ID 1Next program on same day in device B is program 1 at 22:54
B2022-01-01 22:54ID 1 no next program because no additional program was started on the same day in device B
A2022-01-03 23:09ID 1 no next program because no additional program was started on the same day in device A

 

Can anyone tell me how to accomplish this? 

 

Thanks a lot in advance!!!

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

Hi @Opilio2 
Yes you are right. I missed that we are dealing with time rather than date. Please use

NextProgramSameDay column = 
VAR CurrentTimeStamp = 'Table'[Timestamp]
VAR CurrentDate = DATE ( YEAR ( CurrentTimeStamp ), MONTH ( CurrentTimeStamp ), DAY ( CurrentTimeStamp ) )
VAR FilteredDeviceTable =
    FILTER (
        CALCULATETABLE (
            'Table',
            ALLEXCEPT ( 'Table', 'Table'[Device ID] )
        ),
        DATE ( YEAR ( 'Table'[Timestamp] ), MONTH ( 'Table'[Timestamp] ), DAY ( 'Table'[Timestamp] ) ) = CurrentDate
            && 'Table'[Timestamp] > CurrentTimeStamp
    )
VAR NextTimeStamp =
    MINX (
        FilteredDeviceTable,
        'Table'[Timestamp]
    )
VAR NextProgram =
    MINX ( FILTER ( FilteredDeviceTable, 'Table'[Timestamp] = NextTimeStamp ), 'Table'[Program ID] )
RETURN
    NextProgram

1.png

View solution in original post

6 REPLIES 6
tamerj1
Community Champion
Community Champion

Hi @Opilio2 
Yes you are right. I missed that we are dealing with time rather than date. Please use

NextProgramSameDay column = 
VAR CurrentTimeStamp = 'Table'[Timestamp]
VAR CurrentDate = DATE ( YEAR ( CurrentTimeStamp ), MONTH ( CurrentTimeStamp ), DAY ( CurrentTimeStamp ) )
VAR FilteredDeviceTable =
    FILTER (
        CALCULATETABLE (
            'Table',
            ALLEXCEPT ( 'Table', 'Table'[Device ID] )
        ),
        DATE ( YEAR ( 'Table'[Timestamp] ), MONTH ( 'Table'[Timestamp] ), DAY ( 'Table'[Timestamp] ) ) = CurrentDate
            && 'Table'[Timestamp] > CurrentTimeStamp
    )
VAR NextTimeStamp =
    MINX (
        FilteredDeviceTable,
        'Table'[Timestamp]
    )
VAR NextProgram =
    MINX ( FILTER ( FilteredDeviceTable, 'Table'[Timestamp] = NextTimeStamp ), 'Table'[Program ID] )
RETURN
    NextProgram

1.png

tamerj1
Community Champion
Community Champion

@Opilio2 

Try

 

NextProgramSameDay column =
VAR CurrentDate = Table[Timestamp]
RETURN
    COUNTROWS (
        FILTER (
            CALCULATETABLE (
                Table,
                ALLEXCEPT ( Table, Table[Device ID], Table[Timestamp] )
            ),
            Table[Timestamp] > CurrentDate
        )
    )

 

Unfortunately, this does not work but returns an empty column. 

tamerj1
Community Champion
Community Champion

Hi @Opilio2 

if you are looking for a column you can use

NextProgramSameDay column =
COUNTROWS (
    FILTER (
        CALCULATETABLE (
            Table,
            ALLEXCEPT ( Table, Table[Device ID], Table[Timestamp] )
        ),
        Table[Timestamp] > EARLIER ( Table[Timestamp] )
    )
)

Hey @tamerj1 ,
many thanks for your fast reply - this doesn't seem to be the solution, though; your suggestion only delivers blanks.
Additionally, I might have been mistakable, though- I'm looking for the following program ID/ name, given a certain deive ID and the date.

tamerj1
Community Champion
Community Champion

Are you creating a calculated column or w measure?

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.