Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Compare Business days in one month to another

Hi folks,

Looking to get some help with comparing business days in one month to a previous month?

For example, I want to compare the data for 7 working days in September to 7 working days in August. For my application, only Sunday is not a working day.

When I make a selection in my days field I end up having a slightly misleading comparison as 7 working days i.e. 1st to 9th of a month excluding Sunday, may be 6 days for the current month and 7 days for the previous month.

I need to compare the right amount of days i.e. 3 working days in Sept to 3 working days in August.

Find below some code that I have bee using so far for the comparison. The comparison works perfectly fine if I am looking at date ranges i.e. comparing 1st to 20th of one month to another month, but it doesn't work well for comparing specific business days.

Current Month

= sum({$<C_date = {">=$(=monthstart(Max(C_date)))<=$(=Max(C_date)))"}, C_WeekDay -= {'Sunday'} >} Value)  

Previous Month

= sum({$<C_date = {">=$(=monthstart(Max(C_date),-1))<=$(=Addmonths(Max(C_date),-1))"},C_Year=,C_Month=, C_WeekDay -= {'Sunday'}>} Value)

6 Replies
tresesco
MVP
MVP

Are your day names defined like Sun or Sunday?

Not applicable
Author

They are defined like Sun and not Sunday. Sunday was just for illustration

tresesco
MVP
MVP

Then you may want to try mentioning the days accordingly in the set as well, like:

= sum({$<C_date = {">=$(=monthstart(Max(C_date)))<=$(=Max(C_date)))"}, C_WeekDay -= {'Sun'} >} Value) 

If this does not work, please share your sample app.

Not applicable
Author

Thank you for your reply. Including the names of the working days in the expression is the same as excluding Sunday which I am already doing in the expression by doing C_WeekDay - = {'Sunday'}

Just to make myself clearer, with the exclusion of Sunday I can get 6 business days in one week, but sometimes when I compare it to the previous month, I could be comparing 6 days to 5 days depending on when Sunday occurs which makes the comparison misleading.

Hope this makes it clearer.

Regards

tresesco
MVP
MVP

Well, in that case, my approach would be to calculate two variables:

variable1: to decide the number of days to be subtracted from the max date (considering, if there lies a sunday)

variable2: to decide the number of days to be subtracted for the last month (considering, if there lies a sunday)

Once these are calculated in the variable, you can use them in the set analysis to define the range.

Not applicable
Author

I had hoped that this would be easier, but it seems that it can potentially get convoluted which is what I have been trying to avoid.

Thanks for your suggestion