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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
frankhofmans
Helper IV
Helper IV

Classify number of working days between 2 dates

hi PBI community members:

 

i have a data table with a employee ID, the startdate and the end date of a sickness case. i want to present the number of working days in a graph, and i want to classify the number of working days in 3 categories. The way of the classification is depending on wether or not the sickness end date is in or later than the selected period:

 

For example:

 

Employee IDStart dateEnd date
2303-04-202005-04-2020
2704-04-202003-07-2020
3003-03-202010-08-2020
3501-01-202005-01-2020
4005-02-202010-02-2020

 

I want the following table or graph:

 

Class:Q1 2020Q1 2020Q3 2020
0-5 working days710
6-30 working days2100
30-999 working days012732

 

I need the number of working days between start date and end date, but if the end date is later than the end date of the selected period (in this case quaterly), than i need the number of working days between start date and last date of the quarter. So the sickness case of employee 30 (start date 03-03-2020) is classified in Q1 as "5-30 working days", but in Q2 it is classified as "30-999 working days". 

 

Does anyone have a solution for this?

 

Thanks in advance,

 

Regards,

 

Frank

 

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

Hi, @frankhofmans 

According to your description and sample data, I get the expected result through calculated column and matrix, you can take a look at my method and find if it’s useful:

  1. I created these calculated columns:
Q1 2020 =
var _endofquater=DATE(2020,3,31)
var _datediff=DATEDIFF('Table'[Start date],_endofquater,DAY)
var _compare=DATEDIFF('Table'[End date],_endofquater,DAY)
var _value= IF(_compare<0,ABS(_datediff),BLANK())
return
SWITCH(TRUE(),
_value>0&&_value<=5,"0-5 working days",
_value>6&&_value<=30,"6-30 working days",
_value>30&&_value<=999,"30-999 working days",
"Ineligible")
Q2 2020 =
var _endofquater=DATE(2020,6,30)
var _datediff=DATEDIFF('Table'[Start date],_endofquater,DAY)
var _compare=DATEDIFF('Table'[End date],_endofquater,DAY)
var _value= IF(_compare<0,ABS(_datediff),BLANK())
return
SWITCH(TRUE(),
_value>0&&_value<=5,"0-5 working days",
_value>6&&_value<=30,"6-30 working days",
_value>30&&_value<=999,"30-999 working days",
"Ineligible")
Q3 2020 =
var _endofquater=DATE(2020,9,30)
var _datediff=DATEDIFF('Table'[Start date],_endofquater,DAY)
var _compare=DATEDIFF('Table'[End date],_endofquater,DAY)
var _value= IF(_compare<0,ABS(_datediff),BLANK())
return
SWITCH(TRUE(),
_value>0&&_value<=5,"0-5 working days",
_value>6&&_value<=30,"6-30 working days",
_value>30&&_value<=999,"30-999 working days",
"Ineligible")
  1. Then I created a Matrix chart and place columns like this:

v-robertq-msft_0-1608106544635.png

 

v-robertq-msft_1-1608106544643.png

 

And I guess this is what you want.

You can download my test pbix file here

 

Best Regards,

Community Support Team _Robert Qin

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

2 REPLIES 2
v-robertq-msft
Community Support
Community Support

Hi, @frankhofmans 

According to your description and sample data, I get the expected result through calculated column and matrix, you can take a look at my method and find if it’s useful:

  1. I created these calculated columns:
Q1 2020 =
var _endofquater=DATE(2020,3,31)
var _datediff=DATEDIFF('Table'[Start date],_endofquater,DAY)
var _compare=DATEDIFF('Table'[End date],_endofquater,DAY)
var _value= IF(_compare<0,ABS(_datediff),BLANK())
return
SWITCH(TRUE(),
_value>0&&_value<=5,"0-5 working days",
_value>6&&_value<=30,"6-30 working days",
_value>30&&_value<=999,"30-999 working days",
"Ineligible")
Q2 2020 =
var _endofquater=DATE(2020,6,30)
var _datediff=DATEDIFF('Table'[Start date],_endofquater,DAY)
var _compare=DATEDIFF('Table'[End date],_endofquater,DAY)
var _value= IF(_compare<0,ABS(_datediff),BLANK())
return
SWITCH(TRUE(),
_value>0&&_value<=5,"0-5 working days",
_value>6&&_value<=30,"6-30 working days",
_value>30&&_value<=999,"30-999 working days",
"Ineligible")
Q3 2020 =
var _endofquater=DATE(2020,9,30)
var _datediff=DATEDIFF('Table'[Start date],_endofquater,DAY)
var _compare=DATEDIFF('Table'[End date],_endofquater,DAY)
var _value= IF(_compare<0,ABS(_datediff),BLANK())
return
SWITCH(TRUE(),
_value>0&&_value<=5,"0-5 working days",
_value>6&&_value<=30,"6-30 working days",
_value>30&&_value<=999,"30-999 working days",
"Ineligible")
  1. Then I created a Matrix chart and place columns like this:

v-robertq-msft_0-1608106544635.png

 

v-robertq-msft_1-1608106544643.png

 

And I guess this is what you want.

You can download my test pbix file here

 

Best Regards,

Community Support Team _Robert Qin

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

amitchandak
Super User
Super User

@frankhofmans , 2 Steps, First you need create a measure for working day diff and then you need to do dynamic segmentation

Refer this file : https://www.dropbox.com/s/o2v5ekfiw5057do/Working%20date%20between%20Dates%20Measure%20and%20Table.p...

or

https://www.sqlbi.com/articles/counting-working-days-in-dax/

 

Dynamic segmentation: https://youtu.be/CuczXPj0N-k

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.