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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ncraft
Frequent Visitor

"Gaps&Islands" consecutive days in student absences

I am working with a large table of student attendance data that spans mutlipel campuses and school years. 
There is a column for dates and student IDs, where each date entry represents a day the student was marked absent. 
I need a measure or a calculated column that can return whether or not an absense for a given student is consecutive, and for each consecutive absensce, what is the cumulative value of that absense. 
Here is a sample data set: I have highlighted the 3 student ids to show how they are not ordered

ncraft_0-1642099430107.png

Here is an example of what the my desired result would look like

ncraft_1-1642099561104.png

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@ncraft Seems like a varation on Cthulhu or MTBF. Basically, compare the previous row defined by the student id and date. So, essentially, grab the student id and date in the current row. Identify the gaps. Count the number of consequetive rows (difference = 1) between the last gap and the current row. 

Here is the Link to Cthulhu: Cthulhu - Microsoft Power BI Community

I also recently published a detailed video on how to use it and how it works: Microsoft Hates Greg - Cthulhu! - YouTube

If you post sample data as text I can take a closer look.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@ncraft Seems like a varation on Cthulhu or MTBF. Basically, compare the previous row defined by the student id and date. So, essentially, grab the student id and date in the current row. Identify the gaps. Count the number of consequetive rows (difference = 1) between the last gap and the current row. 

Here is the Link to Cthulhu: Cthulhu - Microsoft Power BI Community

I also recently published a detailed video on how to use it and how it works: Microsoft Hates Greg - Cthulhu! - YouTube

If you post sample data as text I can take a closer look.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler (or anyone else reading this who can help),
so request from buisness has added another layer to this problem and I was wondering if you could help me out. I have been scratching my head trying to modify your origional solution but I cant quite get it there.

On our data table that includes the "group" ([student_id])  and the "index" ([date]) there is now a third column [attendance_value] that we need to filter for. [attendance_value] is always equal to 1.0 or 0.5 and buisness does not want rows with value 0.5 to be part of the consecutive count. I can't perform a transform on the data table because the same table is also considered by other measures and visuals in the report. There are also ofcourse some important relationships in the modle between this table and others. I have tried adding an additional helper column but having cuthulhu reference another calcuated column seems to compound the calulation time and make it impossible to execute. I figure there there has got to be a way to correctly include the filter in the cuthulhu code. 
I tried setting it up like this:

 

VAR __group = CALCULATE(MAX('data'[student_id]), 'data'[attendance_value]=1)

and that produces the desired result in some cases but not all. 

 

Here is a sample data set where the [cuthulhu] column is a straight copy+paste of your origional solution. On this sample set, I have added a [desired_cuthulhu] my manualy entering the value in each cell for the outcome I am trying to get [cuthulhu] to return. 
*Note that the [student_id] column here is all of one kind intentionally. 

 

student_iddateattendance_valuecuthuluhdesired_cuthulhu
2691822/1/2021111
2691822/2/2021122
2691822/3/2021133
2691822/4/2021144
2691822/5/2021155
2691822/8/20210.511
2691822/9/2021121
2691822/10/2021132
2691822/11/2021143
2691822/12/2021154
2691822/16/20210.511
2691822/17/2021121
2691822/18/20210.531
2691822/19/2021141
2691822/20/2021152

Wow @Greg_Deckler, this is exactly what I needed.
I didnt have to modify your solution at all. I plugged in [date] for [index] and [student_id] for [animal] and cthulhu worked perfectly.
Thank you so much for your hard work on this (even if it was years ago). Not only will this be valuble for my team, but I can also take some solice knowing I wasnt the only one that went nearly insane working on this problem 😄

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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