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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
JFarq
Helper I
Helper I

Counting how many date ranges have dates that fall within another date range

Hi

 

I'm trying to replicate the following excel table in PowerBI:

 

SampleDashboardTable.png

The table displays the number of absent staff per month in the past 24 months.

The table uses the TODAY() and EOMONTH() excel formulae to generate a 'Month', 'End Of Month' and 'Start Of Month' column.


Then using the following formula it counts how many staff were absent (at any point) in each month:

formula2.png

 

Where Absence_Data2 is my source data of a list of staff with a start and end date for each staff absence period:

SourceData.png

I've tried making a DateTable query in PowerBI to generate a 'Month', 'End Of Month' and 'Start Of Month' column in a powerBI matrix:

PowerBIMatrix1.PNG

I've connected my DateTable query to the Absence_Data2 query as follows:

TablesConnections.PNG

 

From here I'm not sure how to add an 'Absence Occurences' column to my matrix to count how many staff were absent in each month.

 

i.e. count how many absence date ranges of my Absence_Data2 query have dates that fall within the date range of each month of my DateTable query.

 

The source data and powerBI files are available via the follwoing link:

Absence_Occurences_AO_Sample_v5.xlsx

Absence_Dashboard_Sample_v1.pbix

 

Any help or guidance would be much appreciated!

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @JFarq 

Please try formula like:

calculated column:

Absence Occurences per person per month  =
CALCULATE (
    COUNT ( Absence_Data2[Start Date] ),
    ALLEXCEPT (
        Absence_Data2,
        Absence_Data2[Start Date].[Month],
        Absence_Data2[Start Date].[Year],
        Absence_Data2[Forename And Surname]
    )
)

Measure:

count of absence date =
CALCULATE (
    COUNTROWS ( Absence_Data2 ),
    FILTER (
        Absence_Data2,
        Absence_Data2[Start Date] >= MAX ( 'Calendar (UK?)'[StartOfMonth] )
            && Absence_Data2[Start Date] <= MAX ( 'Calendar (UK?)'[EndOfMonth] )
    )
) + 0

(need change the data type of 'Calendar (UK?)'[StartOfMonth], 'Calendar (UK?)'[EndOfMonth] from 'Text' to 'Date')

 

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
v-easonf-msft
Community Support
Community Support

Hi, @JFarq 

Please try formula like:

calculated column:

Absence Occurences per person per month  =
CALCULATE (
    COUNT ( Absence_Data2[Start Date] ),
    ALLEXCEPT (
        Absence_Data2,
        Absence_Data2[Start Date].[Month],
        Absence_Data2[Start Date].[Year],
        Absence_Data2[Forename And Surname]
    )
)

Measure:

count of absence date =
CALCULATE (
    COUNTROWS ( Absence_Data2 ),
    FILTER (
        Absence_Data2,
        Absence_Data2[Start Date] >= MAX ( 'Calendar (UK?)'[StartOfMonth] )
            && Absence_Data2[Start Date] <= MAX ( 'Calendar (UK?)'[EndOfMonth] )
    )
) + 0

(need change the data type of 'Calendar (UK?)'[StartOfMonth], 'Calendar (UK?)'[EndOfMonth] from 'Text' to 'Date')

 

Best Regards,
Community Support Team _ Eason

Thank you very much v-easonf-msft.

Your measure works for me.

I just had to write it out with 'MANUAL End Date' in first line of the second argument of the FILTER() function:

count of absence date = 
CALCULATE (
    COUNTROWS ( Absence_Data2 ),
    FILTER (
        Absence_Data2,
        Absence_Data2[MANUAL End Date] >= MAX ( 'Calendar (UK?)'[StartOfMonth] )
            && Absence_Data2[Start Date] <= MAX ( 'Calendar (UK?)'[EndOfMonth] )
    )
) + 0

To get:

WorkingAbsenceOccurences1.PNG

speedramps
Super User
Super User

In Power BI it is best practice to use a calendar table.

All reports use dates so this is really important skill for you to learn

Click here for free training 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.