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 value from previous rows

I am dealing with an issue to get a value from an earlier row.

 

I need to get the latest [filtered_top_rated] (for each value from the rows that has [page_type_category] = "Browse Page",

 

For each row that has page_type_category] in {"Venue Page", "Time-selection Page"}, I need to get the latest [filtered_top_rated] (that comes before) value from the rows that has [page_type_category] = "Browse Page".

 

[filtered_top_rated] is a filter which if used can be identified only on [page_type_category] = "Browse Page".

 

There is a sequence of actions. Browse page -> Venue Page -> Time-Selection Page. 


I tried to work with EARLIER() function, but couldn't really get the desired result especially with the rows that are more than one row away from "Browse Page"

 

Capture.PNG

 

collector_timeeventfiltered_top_ratedpage_type_categoryvenue_idRANK

10/23/2017 13:11page_viewnBrowse PageNA8
10/23/2017 13:12page_viewnVenue Page4667db920153525e13f996dab3f135ac9
10/23/2017 13:12page_viewnVenue Pagea6f4826fddfe1db6acfe8ca96853675610
10/23/2017 13:12page_viewyBrowse PageNA11
10/23/2017 13:12page_viewnVenue Page538e6735bce5d062e3d5fd4f384cff3f12
10/23/2017 13:13page_viewnTime-selection Page538e6735bce5d062e3d5fd4f384cff3f13
10/23/2017 13:22page_viewnBrowse PageNA14
10/23/2017 13:22page_viewnBrowse PageNA15
10/23/2017 13:22page_viewnBrowse PageNA16
10/23/2017 13:22page_viewnBrowse PageNA17
10/23/2017 13:23page_viewnVenue Pagee7c810dec8b5e2510d29b5bee184b05318
10/23/2017 13:23page_viewyBrowse PageNA19
10/23/2017 13:24page_viewnVenue Pagefbe9bb3254a949e169f85561f410262a20
10/23/2017 13:24page_viewnVenue Page88e9dd50236be091138ad4fdf192dbec21
10/23/2017 13:25page_viewnTime-selection Pagefbe9bb3254a949e169f85561f410262a22
2 ACCEPTED SOLUTIONS
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

There're duplicate times in [collector_time] field so you need to add an index column to build "time" sequence. Click query editor-> Add Column-> Index Column. Then create a calculate column using dax below:

Result = 
IF (
    'Table'[page_type_category] = "Browse Page"
        && 'Table'[collector_time] = MAX ( 'Table'[collector_time] ),
    CALCULATE (
        MAX ( 'Table'[filtered_top_reated] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[collector_time] = MAX ( 'Table'[collector_time] )
        )
    ),
    IF (
        'Table'[page_type_category] IN { "Venue Page", "Time-selection Page" },
        VAR Current_Time_Index = 'Table'[Index]
        VAR Previous_Lastest_Time_Index =
            CALCULATE (
                MAX ( 'Table'[collector_time] ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Index] < Current_Time_Index
                        && 'Table'[page_type_category] = "Browse Page"
                )
            )
        RETURN
            CALCULATE (
                MAX ( 'Table'[filtered_top_reated] ),
                FILTER ( ALL ( 'Table' ), 'Table'[collector_time] = Previous_Lastest_Time_Index )
            )
    )
)

Capture.PNG 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Thank you for the response @v-yuta-msft .  With some adjustments I managed to get the result I desired! Thank you!

 

I have adjusted a bit the code since I realised, that probably I should have given an example with multiple sessions. Additionally to your solution, I edited to find the same session_ID in earlier rows. Also, the last column of sample data, was Ranking (or index) for each session's actions.

 

Filter Y/N = 
IF (
    'GB_Events'[page_type_category] = "Browse Page"
        && 'GB_Events'[collector_time] = MAX ( 'GB_Events'[collector_time] )
        ,
    CALCULATE (
        MAX ( 'GB_Events'[filtered_top_rated] ),
        FILTER (
            ALL ( 'GB_Events' ),
            'GB_Events'[collector_time] = MAX ( 'GB_Events'[collector_time] )
            && GB_Events[session_id] = EARLIER(GB_Events[session_id])
        )
    ),
    IF (
        'GB_Events'[page_type_category] IN { "Venue Page", "Time-selection Page" },
        VAR Current_Time_Index = 'GB_Events'[RANKX Session]
        VAR Previous_Lastest_Time_Index =
            CALCULATE (
                MAX ( 'GB_Events'[collector_time] ),
                FILTER (
                    ALL ( 'GB_Events' ),
                    GB_Events[session_id] = EARLIER(GB_Events[session_id]) &&
                    'GB_Events'[RANKX Session] < Current_Time_Index
                        && 'GB_Events'[page_type_category] = "Browse Page"
                )
            )
        RETURN
            CALCULATE (
                MAX ( 'GB_Events'[filtered_top_rated] ),
                FILTER ( ALL ( 'GB_Events' ), 'GB_Events'[collector_time] = Previous_Lastest_Time_Index )
            )
    )

 

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

There're duplicate times in [collector_time] field so you need to add an index column to build "time" sequence. Click query editor-> Add Column-> Index Column. Then create a calculate column using dax below:

Result = 
IF (
    'Table'[page_type_category] = "Browse Page"
        && 'Table'[collector_time] = MAX ( 'Table'[collector_time] ),
    CALCULATE (
        MAX ( 'Table'[filtered_top_reated] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[collector_time] = MAX ( 'Table'[collector_time] )
        )
    ),
    IF (
        'Table'[page_type_category] IN { "Venue Page", "Time-selection Page" },
        VAR Current_Time_Index = 'Table'[Index]
        VAR Previous_Lastest_Time_Index =
            CALCULATE (
                MAX ( 'Table'[collector_time] ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[Index] < Current_Time_Index
                        && 'Table'[page_type_category] = "Browse Page"
                )
            )
        RETURN
            CALCULATE (
                MAX ( 'Table'[filtered_top_reated] ),
                FILTER ( ALL ( 'Table' ), 'Table'[collector_time] = Previous_Lastest_Time_Index )
            )
    )
)

Capture.PNG 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you for the response @v-yuta-msft .  With some adjustments I managed to get the result I desired! Thank you!

 

I have adjusted a bit the code since I realised, that probably I should have given an example with multiple sessions. Additionally to your solution, I edited to find the same session_ID in earlier rows. Also, the last column of sample data, was Ranking (or index) for each session's actions.

 

Filter Y/N = 
IF (
    'GB_Events'[page_type_category] = "Browse Page"
        && 'GB_Events'[collector_time] = MAX ( 'GB_Events'[collector_time] )
        ,
    CALCULATE (
        MAX ( 'GB_Events'[filtered_top_rated] ),
        FILTER (
            ALL ( 'GB_Events' ),
            'GB_Events'[collector_time] = MAX ( 'GB_Events'[collector_time] )
            && GB_Events[session_id] = EARLIER(GB_Events[session_id])
        )
    ),
    IF (
        'GB_Events'[page_type_category] IN { "Venue Page", "Time-selection Page" },
        VAR Current_Time_Index = 'GB_Events'[RANKX Session]
        VAR Previous_Lastest_Time_Index =
            CALCULATE (
                MAX ( 'GB_Events'[collector_time] ),
                FILTER (
                    ALL ( 'GB_Events' ),
                    GB_Events[session_id] = EARLIER(GB_Events[session_id]) &&
                    'GB_Events'[RANKX Session] < Current_Time_Index
                        && 'GB_Events'[page_type_category] = "Browse Page"
                )
            )
        RETURN
            CALCULATE (
                MAX ( 'GB_Events'[filtered_top_rated] ),
                FILTER ( ALL ( 'GB_Events' ), 'GB_Events'[collector_time] = Previous_Lastest_Time_Index )
            )
    )

 

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.