3 Replies Latest reply on Mar 29, 2018 9:38 AM by Paul Sutherland

# Calculate number of weekdays between two dates

Hello

I am trying to calculate two date difference:

1) Number of Weekdays (exclude weekends) between today() and the beginning of the quarter. For example, if today is 29th March 2018 and beginning of quarter is 1/1/2018, I am using this calculation but it doesn't seem to work:

DATEDIFF('weekday',DATETRUNC('quarter',TODAY()),TODAY())

2) Number of Weekdays (exclude weekends) between the beginning of the quarter and end of a quarter: Not sure how to calculate the end of a quarter in tableau.

Thanks

Chandan Mishra

• ###### 1. Re: Calculate number of weekdays between two dates

Chandan... it looks like your first calculated field is correct. You just need to change the value of the field to be an ATTR() when it is in the view Re: your second point... Tableau has published a guide for getting last day of month or quarter: Finding End of Month or End of Quarter Dates | Tableau Software

Here is the relevant bit

### To find and use end of quarter date:

1. Create calculated field with the following calculation:
`DAY([Date] + 1) = 1 AND (MONTH([Date] + 1) = 4 OR MONTH([Date] + 1) = 7 OR MONTH([Date] + 1) = 10 OR MONTH([Date] + 1) = 1)l`
2. Add calculated field to the filters shelf.
3. Select True.
• ###### 2. Re: Calculate number of weekdays between two dates

Hello Paul

Thanks for your reply. I was using AGG but now this works. Only thing is this is calculating number of days instead of number of weekdays. Any method through which I can exclude the number of days on weekends.

Also for the second part of the question, how to calculate the difference in number of weekdays between start and end of quarter?

Thanks

Chandan Mishra

• ###### 3. Re: Calculate number of weekdays between two dates

You are right that is including weekends! It shouldn't be though because we have specificied 'weekday' as the date_partition. I will have to look at this further

I edited my answer to include a response to Part 2 of your question