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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Subtract days in month by absence days

Month and YearPERSON ID 135PERSON ID 721PERSON ID 1003Total
January 2019  (31-4)27
February 2019(28-6)  22
March 2019(31-1)(31-4) 26
June 2019  (30-23)7
July 2019  (31-20)11
August 2019 (31-2) 29
September 2019  (30-4)26

 

I've created a cross join table to count the difference between two dates and present them in a month format (above):

 
Step1. Calendar date = CALENDAR(MIN('Table'[DATE_START]),MAX('Table'[DATE_END]))
 
Step 2. Cross Join =
FILTER (
CROSSJOIN ( 'Table', 'Calendar date' ),
[Date] >= 'Table'[DATE_START]-1
&& [Date] < 'Table'[DATE_END]
)
 
Step 3. Month Name = 'Cross Join'[Date].[Month]
 
Is there a way to subtract the number of days in each month by the absence figures I've found in each month? e.g. 31days in January - 6 absence days
 
Days in Month = DAY ( EOMONTH ( [Month and Year], 0 ))
 
File attached
1 ACCEPTED SOLUTION

Hi @Anonymous ,

I made upadate on the formula of Meaure 3, now it can get the correct result...

Measure 3 =
VAR _Month =
    EOMONTH (
        DATE ( LEFT ( MAX ( 'DimDate'[Month Year] )4 )VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] )2 ) )1 ),
        0
    )
VAR _lastday =
    COUNTROWS (
        FILTER (
            'DimDate',
            'DimDate'[Date] >= DATE ( YEAR ( _Month )MONTH ( _Month )1 )
                && 'DimDate'[Date] <= _Month
                && NOT ( WEEKDAY ( [Date] ) IN { 17 } )
        )
    )
RETURN
    IF ( ISBLANK ( [AbsentByDay] )BLANK ()_lastday ) - [AbsentByDay]

Subtract days in month by absence days(Updated).JPG

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

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.

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@Anonymous , refer my file , where I have distributed leave across days

https://www.dropbox.com/s/bqbei7b8qbq5xez/leavebetweendates.pbix?dl=0

 

I have not checked your file

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

If I have created a measure:

AbsentByDay = CALCULATE(countx(SUMMARIZE(filter(CROSSJOIN('Table','DimDate'),'DimDate'[Date] >= 'Table'[DATE_START] && 'DimDate'[Date]<= 'Table'[DATE_END]),'Table'[PERSON_ID],'DimDate'[Date]),'DimDate'[Date]),FILTER(DimDate,DimDate[WorkingDays] <>BLANK()))
 
Is there a way to edit this measure to subtract days in month (e.g. 31days in August 2019 - 5 absences):
 
Days in Month = DAY ( EOMONTH ( [Month and Year], 0 ))
 

Hi @Anonymous ,

I created two measures as below to get the working days and applied the new measure [Measure 2] on the matrix to replace the measure [AbsentByDay]. You can find the details in the attachment.

Measure = 
VAR _lastday =
    DAY (
        EOMONTH (
            DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
            0
        )
    )
RETURN
    IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]
Measure 2 = SUMX(VALUES('DimDate'[Month Year]),[Measure])

Subtract days in month by absence days.JPG

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

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.
Anonymous
Not applicable

This works great for full month figures. Thank you so much for this. Is there a way to apply just working days to this?

 

e.g. NOT WEEKDAY( 'DimDate'[Date] ) IN { 1,7 }

 

to

 

Measure =
VAR _lastday =
DAY (
EOMONTH (
DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
0
)
)
RETURN
IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]
Anonymous
Not applicable

I have an almost 100% solution to this: 

Measure 3 =

VAR _Month =
EOMONTH (
DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
0
)

VAR _lastday=
COUNTROWS(
FILTER(
CALENDAR( EDATE(_Month , -1)+1 , _Month ),
NOT( WEEKDAY( [Date] ) IN { 1,7 })
)
)

RETURN
IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]
 
However there are some values that are not calculating correctly, can anyone help?
Working date - absence.PNG
 

Hi @Anonymous ,

I made upadate on the formula of Meaure 3, now it can get the correct result...

Measure 3 =
VAR _Month =
    EOMONTH (
        DATE ( LEFT ( MAX ( 'DimDate'[Month Year] )4 )VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] )2 ) )1 ),
        0
    )
VAR _lastday =
    COUNTROWS (
        FILTER (
            'DimDate',
            'DimDate'[Date] >= DATE ( YEAR ( _Month )MONTH ( _Month )1 )
                && 'DimDate'[Date] <= _Month
                && NOT ( WEEKDAY ( [Date] ) IN { 17 } )
        )
    )
RETURN
    IF ( ISBLANK ( [AbsentByDay] )BLANK ()_lastday ) - [AbsentByDay]

Subtract days in month by absence days(Updated).JPG

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

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.

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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