Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Nomad
Regular 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..

 

Nomad_1-1688808757820.png

 

Let say i want to count/sum (?) all the time a person was in sick leave, i can see how to count all value, but i would only want the last consecutive date that person was in sick leave, for the exemple : 

 

Adel was on sickleave for 4 consecutive days from 16/02/2023 - 19/02/2023 and also for 3 consecutive days from 21/03/2023 - 23/03/2023.

But i only have an interset to see last group of days she was on sick leave.

 

The end result should be something like that :

 

Nomad_2-1688809028991.png

 

Another exemple for Bastien :

 

He was in sick leave several time but i only need too see when was the last time and for how long.

 

Nomad_3-1688809242107.png

 

Im hope im clear enough in the exemple.

 

I attach the test model for some clarity.

 

https://drive.google.com/file/d/1XxzyYgdei3UuisDEqjPZ8aaJzKHFOpen/view?usp=drive_link

 

Thank you for your support !

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

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 )
    )

 

MFelix_0-1688835832119.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

6 REPLIES 6
MFelix
Super User
Super User

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 )
    )

 

MFelix_0-1688835832119.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Hi, im going to go with that.

 

@MFelix and @danextian thank youu both for your time!

danextian
Super User
Super User

Hi @Nomad ,

 

Please make your link public.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

oh right, my bad, done!

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.

 

danextian_0-1688831032536.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Amazing, thanks!

 

There is also a way to only display the last "latest sick leave", and not there previuous one ?

Nomad_0-1688835091331.png

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.