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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Leaves taken in a month

Hi Community,

 

I need help to create a measure to calculate 'total leaves taken' like following (ignore weekends & public holidays):

for example:  emp B took 21 leaves in Sep, 31 leaves in oct & 2 leaves in Nov.

 

ExcelPBI_0-1636592659245.png

My pbi sample file:

https://1drv.ms/u/s!Ag919_pO_UKrgSNq3-uQTF6KrCRO?e=jcooHH

 

Many thanks

1 ACCEPTED SOLUTION

Hi,

I am not sure if I understood your question correctly.

Please check the below picture and the attached pbix file.

I disconnected the two tables.

 

Picture1.png

 

Leave days count: =
VAR startdate =
MAX ( 'Table'[leave start date] )
VAR enddate =
MAX ( 'Table'[leave end date] )
VAR calendartable =
FILTER ( Datedim, Datedim[Date] >= startdate && Datedim[Date] <= enddate )
RETURN
COUNTROWS ( calendartable )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

7 REPLIES 7
Kumail
Post Prodigy
Post Prodigy

Hello @Anonymous 

 

Seems there is something missing in the data. Emp B took leaves from 10/09/2021 to 2/11/2021 and 2/10/2021 to 6/10/2021 for the same year that couldn't be possible.

 

Hope this helps to clarify.

 

Regards

Kumail Raza

Did this help? Kudos are appreciated

Anonymous
Not applicable

@Kumail thanks for letting me know. I have corrected it now.

Jihwan_Kim
Super User
Super User

Hi,

I created some more columns in the datedim table and I marked the datedim table as datetable.

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Leave days count split by month: =
VAR startdate =
MAX ( 'Table'[leave start date] )
VAR enddate =
MAX ( 'Table'[leave end date] )
VAR datetable_between_startenddate =
FILTER (
ALL ( Datedim ),
Datedim[Date] >= startdate
&& Datedim[Date] <= enddate
)
VAR add_leavecount =
ADDCOLUMNS ( datetable_between_startenddate, "@leavecount", 1 )
VAR groupbymonth =
GROUPBY (
add_leavecount,
Datedim[Month name CC],
Datedim[Month number CC],
"@monthlycount", SUMX ( CURRENTGROUP (), [@leavecount] )
)
RETURN
CONCATENATEX (
groupbymonth,
[@monthlycount] & " days in " & Datedim[Month name CC],
" / ",
Datedim[Month number CC]
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

@Jihwan_Kim  thanks for your solution. Really appreciate it. Just one thing, I want the data to be presented in a matrix like below:

Note that I have updated emp B leaves 

 

ExcelPBI_0-1636608176908.png

 

updated pbi file:

https://1drv.ms/u/s!Ag919_pO_UKrgSNq3-uQTF6KrCRO?e=MswKaF

 

I'll be very grateful if you could help me presenting the data like above.

 

Thanks

 

Hi,

I am not sure if I understood your question correctly.

Please check the below picture and the attached pbix file.

I disconnected the two tables.

 

Picture1.png

 

Leave days count: =
VAR startdate =
MAX ( 'Table'[leave start date] )
VAR enddate =
MAX ( 'Table'[leave end date] )
VAR calendartable =
FILTER ( Datedim, Datedim[Date] >= startdate && Datedim[Date] <= enddate )
RETURN
COUNTROWS ( calendartable )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

amitchandak
Super User
Super User

@Anonymous ,

You can find work date like

Work Day = COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

 

 

But for holiday , better to use a calendar

refer

How to calculate Business Days/ Workdays, with or without date table: https://youtu.be/Qv4wT8_P-AA

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

@amitchandak thanks, but this doesn't help me much.

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.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

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

Jan NL Carousel

Fabric Community Update - January 2025

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