Forum Discussion
New column to populate previous value
I have a table similar to below, i would like to add a 'new column' to popular 'Previous Status' by ID and Date. In Excel, I can sort by ID and Date, then insert a funcation = previous value. how to do it in DAX? thanks.
- Anonymous9 years ago
Anonymous,
Right Click your table in Fields panel and select “New Column”, then enter the following DAX.
Previous Status = var previous= CALCULATE(FIRSTNONBLANK(Table[Status],""),FILTER(Table,Table[ID]=EARLIER(Table[ID])&& Table[Date]<EARLIER(Table[Date]))) return IF(ISBLANK(previous),BLANK(), previous)
Regards,
Lydia
3 Replies
- AnonymousNot applicable
Anonymous,
Right Click your table in Fields panel and select “New Column”, then enter the following DAX.
Previous Status = var previous= CALCULATE(FIRSTNONBLANK(Table[Status],""),FILTER(Table,Table[ID]=EARLIER(Table[ID])&& Table[Date]<EARLIER(Table[Date]))) return IF(ISBLANK(previous),BLANK(), previous)
Regards,
Lydia- AnonymousNot applicable
on the 'solved solution' I get:
The syntax for 'Table' is incorrect. (DAX(var previous= CALCULATE(FIRSTNONBLANK(Table[Status],""),FILTER(Table,Table[ID]=EARLIER(Table[ID])&& Table[Date]<EARLIER(Table[Date])))return IF(ISBLANK(previous),BLANK(), previous))).
- AnonymousNot applicable
I have the same requirement, but the IDs & Dates are not sorted. Can you provide a formula which works even on unsorted data