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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
chethan
Resolver III
Resolver III

Date Duration exclude weekends

Hi All,

 

i need a DAX formula to calculate the Date Duration by Excluding the Weekends (Saturday & Sunday) Below is the Table View.

 

TableName : WeeklyReport

 

Please help on this 

 

Order  NumberOpened Date/Time Closed Date /Time Days Duration
8064528599/30/2015 14:3910/19/2015 12:2214
80645286010/20/2015 17:2810/22/2015 10:383
8064528615/20/2015 16:135/27/2015 10:296
80645286211/3/2015 11:4711/5/2015 11:323
8064528638/18/2015 17:059/18/2015 12:2324
8064528644/20/2015 13:184/23/2015 14:224
80645286510/1/2015 12:2610/5/2015 11:083
8064528664/1/2015 2:044/23/2015 16:2417
80645286711/23/2015 12:2812/28/2015 12:2726
80645286811/23/2015 10:5311/30/2015 18:066
8064528694/23/2015 17:224/29/2015 11:025
8064528704/23/2015 12:584/27/2015 10:093

 

Thanks in advance.

Regards,

Chethan K

12 REPLIES 12
v-haibl-msft
Microsoft Employee
Microsoft Employee

@chethan

 

If you also want to exclude non-working hours, you can take a look at this thread, and transfer the hours to days.

 

Best Regards,

Herbert

BhaveshPatel
Community Champion
Community Champion

Hi Chethan,

 

You should import the Dates Table in your data model for the implementation of my solution.

 

Step 1: As Part of the calculation, Create IsWorkDay Calculated Column in Your Dates Table

 

IsWorkDay=SWITCH(WEEKDAY([Date]),1,0,7,0,1)

 

Step 2: Create Days Duration excluding Weekends by creating another calculated column in your orders table

 

Days Duration excluding Weekends=CALCULATE(SUM(Dates[IsWorkDAY]),
                                                                                       DATESBETWEEN(Dates[Date],
                                                                                          OrdersTable[Opened Date/Time ],
                                                                                              OrdersTable[Closed Date /Time ] )
                                                                                      )

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

is there a way i can do a reversal on the same thing that you explained above - I have a date table and i am able to calculate working days.(0s for weekends and 1's for Weekdays). I need to add 5 days to my start date and and pick the appropriate working date from the date table so that it gives me an "Expected Completion Date" that takes account of weekends.  

Hi @BhaveshPatel

Thanks for replay.

 

 

I Have Created a Dates Table in your data model But its not working please help me.. Below is the screenprint

 

 

1.JPG2.JPG3.JPG

 

Thanks 

 

Regards,

Chethan K

 

Anonymous
Not applicable

Instead of summing the [Date] column in your table you should sum your newly created column [IsWorkDay]

 

*Edit* - It also looks as you have created the [IsWorkDay] in your fact table instead of in the date calendar table. Take a closer look to the proposed solution in the first reply. 

 

Br,

Magnus

is there a way i can do a reversal on the same thing that you explained above - I have a date table and i am able to calculate working days.(0s for weekends and 1's for Weekdays). I need to add 5 days to my start date and and pick the appropriate working date from the date table so that it gives me an "Expected Completion Date" that takes account of weekends.  

I didnt get can you please create a sample file & can you send me if u dont mind.

Anonymous
Not applicable

Here is a very simple model that shows same scenario as you have and you can see all calculations I have made to make it work. Please note that the function DatesBetween will return a table that includes both the starting date and the ending date! Thus you need to consider how you define the duration (with starting/ending date included or vice versa)

Create a column with 1 for weekdays and 0 for weekendsCreate a column with 1 for weekdays and 0 for weekendscalculate number of days from starting date until ending date without weekendscalculate number of days from starting date until ending date without weekends 

Hi,

Thanks so much for all this valuable inputs, I'm trying to use it, however it is not working for all the cases, let me show... 

Highly appreaciate any help!

 

I'm using:

IsWorkDay = SWITCH(WEEKDAY([Date]);1;0;7;0;1)

 

Days Duration excluding Weekends = CALCULATE(SUM(calendario[IsWorkDAY]);DATESBETWEEN(calendario[Date];'Raw Data'[INCIDENT Submit Date];'Raw Data'[INCIDENT Closed Date]))

 

Below some examples of wrongly 'Days Duration Excluding Weekends' calculation:

image.png

 

Thanks

Hi @Anonymous

 

I just followed your steps and i created the Dates (Calender function) & Is work day (your screenshot function)

i created a column with number of weekday function

 

Out is wrong ??

 

i enclosed the screen shot for your referenceDDiff2.JPGDDiff2a.JPGDDiff2b.JPG

 

Please help me out this

 

Urgent requirement

Hi @Anonymous ,

 

For which field (OpenDate or ClosedDate)  i have to create a column with IsWeekday function

 

Here we have only two date fields OpenDate  &  CloseDate

Anonymous
Not applicable

@ssvr This proposed solution is based on the assumption that you have a separate date table. And it's for that date table you create the IsWeekday column, not for the OpenDate or the CloseDate in your fact table.

 

Br,

Magnus

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

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.