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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Vantage111
Frequent Visitor

Measure for number of absences on any date

I have a table called ABSENCES with a column for start_date and end_date when an employee has been absent.

I would like to graph the total number of staff absence on any given date using my CalendarTAB[date] table.

 

I would also like to produce a 12 Month moving average of Monthly Absences.

 

Thanks in expectation 😉

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Vantage111 ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can follow the steps below to get it:

AbsenceCount = 
CALCULATE(
    DISTINCTCOUNT(ABSENCES[staff]),
    FILTER(
        ABSENCES,
        ABSENCES[start_date] <= MAX(CalendarTAB[date]) && 
        ABSENCES[end_date] >= MAX(CalendarTAB[date])
    )
)
MovingAvgAbsences = 
VAR _date =
    SELECTEDVALUE ( 'CalendarTAB'[Date] )
VAR _eodate =
    EOMONTH ( _date, -11 )
VAR _sdate =
    DATE ( YEAR ( _eodate ), MONTH ( _eodate ), 1 )
RETURN
    AVERAGEX (
        FILTER (
            ALLSELECTED ( CalendarTAB ),
            'CalendarTAB'[Date] >= _sdate
                && 'CalendarTAB'[Date] <= EOMONTH ( _date, 0 )
        ),
        [AbsenceCount]
    )

vyiruanmsft_0-1705472728200.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thnks for the response @v-yiruan-msft and @BA_Pete . I think so far we have all got to roughly the same point, but not quite what I'm looking for - applied both solutions to my data. I think what I am seeing is only the first day of absence (or last) rather than all of the days in that absense instance.

See my snip below.

S1 is off for two days, at the same time S2 is off for three days etc, what I am looking to display are those combined absences_on_the_day and the moving average of that number - there is another column in the ABSENCES table that may help, deducted which is the number of days deducted for this absence - S1=2, S2=3, S3=1 etc.

Vantage111_0-1705488046839.png

 

BA_Pete
Super User
Super User

Hi @Vantage111 ,

 

You can use the following MEASURE structure to work out basically any calculation at a given point in time:

_noofAbsentAtDate = 
VAR __cDate = MAX(CalendarTAB[date])
RETURN
CALCULATE(
    DISTINCTCOUNT(ABSENCES[EmployeeNumber]),
    FILTER(
        ABSENCES,
        ABSENCES[start_date] <= __cDate
        && ( ABSENCES[end_date] > __cDate || ISBLANK(ABSENCES[end_date]) )
    )
)

 

You need to use a column from your CalendarTAB table as the axis in any visual along with this type of measure for it to work. You also need to ensure that your CalendarTAB table IS NOT related to your ABSENCES table or that the relationship is inactive. If the table must be actively related, you can use CROSSFILTER to switch it off, something like this:

_noofAbsentAtDate = 
VAR __cDate = MAX(CalendarTAB[date])
RETURN
CALCULATE(
    CALCULATE(
        DISTINCTCOUNT(ABSENCES[EmployeeNumber]),
        FILTER(
            ABSENCES,
            ABSENCES[start_date] <= __cDate
            && ( ABSENCES[end_date] > __cDate || ISBLANK(ABSENCES[end_date]) )
        ),
    CROSSFILTER(CalendarTAB[date], ABSENCES[YourRelatedColumn], None)
)

 

In terms of your 12 Month average, you can just adjust the calculation that's evaluated and the date ranges that are filtered to get what you want.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors