Forum Discussion
Nomad
3 years agoRegular Visitor
Count consecutive value from last date
Hi everyone, Not sure how to approch this in powerbi. I have a table with people and all there vacation, sick days, formation, etc.. Let say i want to count/sum (?) all the time ...
- 3 years ago
Hi Nomad ,
Try the following:
- Add a column with the following code:
Consecutive Days = VAR temptable = FILTER ( ESTIMATED_DAILY_ABSENCE, ESTIMATED_DAILY_ABSENCE[DATE]< EARLIER ( ESTIMATED_DAILY_ABSENCE[DATE] ) && ESTIMATED_DAILY_ABSENCE[FIRST_NAME] = EARLIER ( ESTIMATED_DAILY_ABSENCE[FIRST_NAME] ) ) RETURN DATEDIFF ( MAXX ( temptable, ESTIMATED_DAILY_ABSENCE[DATE] ), ESTIMATED_DAILY_ABSENCE[DATE], DAY )This will return the number of days from last sick leave
Now add this measures:
last day of sick = VAR temptable = FILTER ( ESTIMATED_DAILY_ABSENCE, ESTIMATED_DAILY_ABSENCE[Consecutive Days] > 1 ) VAR datetop = MAXX ( temptable, ESTIMATED_DAILY_ABSENCE[DATE] ) RETURN MAXX ( FILTER ( ESTIMATED_DAILY_ABSENCE, ESTIMATED_DAILY_ABSENCE[DATE] >= datetop ), ESTIMATED_DAILY_ABSENCE[DATE] ) Number of days = VAR temptable = FILTER ( ESTIMATED_DAILY_ABSENCE, ESTIMATED_DAILY_ABSENCE[Consecutive Days] > 1 ) VAR datetop = MAXX ( temptable, ESTIMATED_DAILY_ABSENCE[DATE] ) RETURN COUNTROWS ( FILTER ( ESTIMATED_DAILY_ABSENCE, ESTIMATED_DAILY_ABSENCE[DATE] >= datetop ) )
Nomad
3 years agoRegular Visitor
oh right, my bad, done!
danextian
3 years agoSuper User
So I took the liberty to just based the proposed solution on your first screenshot. This makes use of several helper columns and scanning of the table several times. Please see attached pbix for the details.
- Nomad3 years agoRegular Visitor
Amazing, thanks!
There is also a way to only display the last "latest sick leave", and not there previuous one ?