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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.