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 September 15. Request your voucher.

Reply
JHart91
Frequent Visitor

Counting Most Recent Rate of Consecutive Absence

Hi all,

 

I have a dataset that tracks the absence rate of students in my school and I am attempting to calculate the number of consecutive days of absence (this includes if a students is absent on the current day, then their count would be 1).

 

Each day is counted twice (i.e. there is an AM and a PM registration slot) so if a student is absent for only half a day I would like the counter to reset to 0. 

 

Some kind souls have already helped me with this measure (see below) but at the moment it only returns the highest occuring number of consecutive days for each student as opposed to the most recent. 

 

In essence I only want it to show how many students are absent on the most recent date and for those students, how many days they have been off since their last day in school.

 

Flag = 
var _cur_date = ('All attendance'[Date])
var _id = ('All attendance'[UPN])
var _t = SELECTCOLUMNS( FILTER('All attendance','All attendance'[UPN]= _id && 'All attendance'[Date]=_cur_date), "Statistical value", 'All attendance'[Statistical value])
return
IF( {"Absent"} in _t , 1, 0) 
Measure = var _t =  FILTER('All attendance' , 'All attendance'[Flag] =1)
var _max_1_date = MAXX(_t , [Date])
var _t2 = FILTER('All attendance','All attendance'[Flag]=0 && 'All attendance'[Date]< _max_1_date)
var _max_0_date = MAXX(_t2,[Date])
var _t3 = FILTER('All attendance', 'All attendance'[Date]<= _max_1_date && 'All attendance'[Date]>_max_0_date)
return
IF(_max_1_date = BLANK() , 0 , IF(_max_0_date=BLANK() , COUNTROWS(_t)/2 , COUNTROWS(_t3)/2 ))

 For reference 'UPN' is the unique reference number for each student.

 

Thanks in advance!!

Jamie

2 REPLIES 2
amitchandak
Super User
Super User

@JHart91 , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Check if this can help

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

 

Continuous streak : https://youtu.be/GdMcwvdwr0o

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

Good morning,

 

The table below shows what the current data looks like with some examples - it is currently set to refresh each day:

UPNDateDescriptionStatistical Value
12316/1/23MorningPresent
12316/1/23AfternoonPresent
12315/1/23MorningPresent
12315/1/23AfternoonPresent
12416/1/23MorningAbsent
12416/1/23AfternoonAbsent
12516/1/23MorningPresent
12515/1/23MorningAbsent
12515/1/23AfternoonAbsent
12514/1/23MorningAbsent
12514/1/23AfternoonAbsent
12616/1/23MorningAbsent
12615/1/23MorningAbsent
12615/1/23AfternoonAbsent
12614/1/23MorningAbsent
12614/1/23AfternoonPresent

 

In terms of output from the examples I have put above I was hoping it would look something like this:

UPN#Consecutive Days AbsentLast Date Present
123016/1/23
124115/1/23
125016/1/23
126214/1/23

 

So using the above examples to illustrate, student 124 is absent on the current day (but was here the day before) so his count is 1, 125 had 2 days off previously but he is now present on the current day so his count should return to 0 and 126 was in for the afternoon on the 14th so his count should be at 2 as well.

 

Hope this makes sense.

 

Thanks,

Jamie

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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