Forum Discussion
Get previous row value in new column
- 8 years ago
Sample data would help but perhaps something like:
Previous = var PreviousDate = MAXX(FILTER(ALL(ddd),EARLIER(ddd[Date]) > ddd[Date] ),ddd[Date]) Return CALCULATE(MAX(ddd[NewUsers]),FILTER(ddd,ddd[Date] = PreviousDate))
You need to FILTER the table as you are doing but then get the MAXX of your date of those filtered rows and then return the value for that row. See my article on Mean Time Before Failure (MTBF) which uses EARLIER in this way: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586
- Anonymous8 years agoNot applicable
Thanks.. I visited the link and I get your point on getting the Max previous date first and then fetching corresponding value but how to do that in a single DAX formula, still struggling. If you can help.. I tried something like below but it gave all blank values.
Previous = var PreviousDate = CALCULATE(MAX(ddd[Date]),FILTER(ddd,EARLIER(ddd[Date]) > ddd[Date] ))
Return CALCULATE(FIRSTNONBLANK(ddd[NewUsers],""),ddd[Date] = PreviousDate)
- Greg_Deckler8 years ago
Community Champion
Sample data would help but perhaps something like:
Previous = var PreviousDate = MAXX(FILTER(ALL(ddd),EARLIER(ddd[Date]) > ddd[Date] ),ddd[Date]) Return CALCULATE(MAX(ddd[NewUsers]),FILTER(ddd,ddd[Date] = PreviousDate))
- Anonymous8 years agoNot applicable
Thanks. works now! I was close but didn't get what was missing from mine one. I have used MAX instead of MAXX and not used FILTER explicitly in return...
Previous = var PreviousDate = CALCULATE(MAX(ddd[Date]),FILTER(ddd,EARLIER(ddd[Date]) > ddd[Date] ))
Return CALCULATE(MAX(ddd[NewUsers]),ddd[Date] = PreviousDate)