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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dejate
New Member

Total count of dates that meet a condition and calculating current date streak.

Hi all,

I'm a beginner with PowerBi and looking for some guidance.

I'm working on a student attendance report and need to simply calculate total sickness "days"  per student.
 
Each student can have multiple register marks on each day.
 
As a first step, I need to simply calculate if a student has at least 1 or more "Sick" mark in the day to return a "1" for Sick day.
 
Data example as follows:
StudentSubject CodeDateRegister Mark
1001MATH2222/09/2022Sick
1001GEO2222/09/2022Sick
1001PHY2222/09/2022Sick
1001MATH2221/09/2022Present
1001GEO2221/09/2022Present
1001PHY2221/09/2022Present
1001MATH2218/09/2022Sick
1001GEO2218/09/2022Present
1001PHY2218/09/2022Present
1001MATH2216/09/2022Present
1001GEO2216/09/2022Present
1001PHY2216/09/2022Present
1002MATH2222/09/2022Present
1002GEO2222/09/2022Present
1002PHY2222/09/2022Present
1002MATH2221/09/2022Present
1002GEO2221/09/2022Present
1002PHY2221/09/2022Present
1002MATH2218/09/2022Present
1002GEO2218/09/2022Present
1002PHY2218/09/2022Present
1002MATH2216/09/2022Sick
1002GEO2216/09/2022Present
1002PHY2216/09/2022Present
 
In the above data, I would expect to return.
 
StudentTotal Sick daysCurrent Sickness Streak
100121
100210

 

Once I have calculated total sick days, a trickier challenge will be to calculate the students currently on a "Current Sickness Streak" which is a running total of consecutive sickness with no full present days.
 
I don't think i can use DateDiff, as the dates are not in consecutive day sequence, eg there are gaps in between when a lesson is held.
 
Any advice to point me to the best approach would be greatly appreciated.

Thanks in advance

dejate - UK
4 REPLIES 4
Anonymous
Not applicable

Hi  @dejate ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a measure as below to get Total Sick days:

Total Sick days = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Date] ),
    FILTER ( 'Table', 'Table'[Register Mark] = "Sick" )
)

2. Follow the steps below to get Current Sickness Streak

1) Create a calculated column as below to judge if the sickness is steak on one whole day

Flag = 
VAR _ccount =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Subject Code] ),
        FILTER (
            'Table',
            'Table'[Student] = EARLIER ( 'Table'[Student] )
                && 'Table'[Date] = EARLIER ( 'Table'[Date] )
        )
    )
VAR _sickcount =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Subject Code] ),
        FILTER (
            'Table',
            'Table'[Student] = EARLIER ( 'Table'[Student] )
                && 'Table'[Date] = EARLIER ( 'Table'[Date] )
                && 'Table'[Register Mark] = "Sick"
        )
    )
RETURN
    IF ( _ccount = _sickcount, 1, 0 )

yingyinr_0-1664178332840.png

2) Create a measure as below to get Current Sickness Streak

Current Sickness Streak = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Date] ),
    FILTER ( 'Table', 'Table'[Flag] = 1 )
) + 0

yingyinr_1-1664178454986.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Thnaks for your reply @Anonymous  - Your measure for Total Sick days worked great, thnaks for that.

But the consecutive sick day measure just seems to return a 1 Flag for every day in my data. It maybe my grouping, so still trying to work through this, but thanks for your suggestion.

I'm also working through @amitchandak suggestion from https://youtu.be/GdMcwvdwr0o

Thanks both, Ill post my update 

Anonymous
Not applicable

Hi @dejate ,

Thanks for your feedback. So do you get the final solution for your problem now? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.

Best Regards

amitchandak
Super User
Super User

@dejate ,

refer if this can help Continuous streak: https://youtu.be/GdMcwvdwr0o

 

https://community.powerbi.com/t5/Community-Blog/Power-BI-Continuous-Streak-With-One-Day-Break/ba-p/1...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.