Forum Discussion
ArvindJha
1 year agoHelper III
Fetch data from previous row
Hi Team, I want to fetch data from previous row and create some if condition based on the values , it should restart for every patient and also be similar to Qlik peek function , thanks Input: ...
- 1 year ago
Hey ArvindJha ,
I use the below DAX to create a calculated columnWEIGHT_ = var currentPatientID = 'Table'[PATIENTID] var currentSite = 'Table'[SITE] var prevDate = maxx( SELECTCOLUMNS( FILTER( WINDOW( 1, abs, -1, rel, SUMMARIZE( ALLSELECTED( 'Table' ), 'Table'[PATIENTID], 'Table'[SITE], 'Table'[DATE], 'Table'[WEIGHT] ), ORDERBY( 'Table'[DATE] , ASC), PARTITIONBY( 'Table'[PATIENTID] , 'Table'[SITE]) ), NOT( ISBLANK( 'Table'[WEIGHT] ) ) ), "d" , [DATE] ) , [d] ) return CALCULATE( MAX('Table'[WEIGHT]), ALL('Table'), 'Table'[PATIENTID] = currentPatientID, 'Table'[SITE] = currentSite, 'Table'[DATE] = prevDate )The table looks like this
Hopefully, this provides what you are looking for.
If not, read this article: https://www.minceddata.info/2024/03/09/my-favorite-windowing-function-window/
Regards,Tom
Kedar_Pande
1 year agoSuper User
Go to Trasnform Data.
Go to Add Column > Index Column > From 1.
Right-click and choose Fill Down to fill missing values from the previous non-null value for each patient.
Go to Transform > Group By > Select All Rows.
Use a custom column to fetch previous values with:
if [Index] = 1 then [HEIGHT] else Table.SelectRows(PreviousStep, each _[Index] = [Index]-1){0}[HEIGHT]
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn