Forum Discussion
Get value from previous rows
- 6 years ago
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 ) ) ) )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.
- Anonymous6 years ago
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 ) ) )
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 )
)
)
)
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.
- Anonymous6 years agoNot 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 ) ) )