Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count days in selected months

I wants to compare sales figures compared to a daily budget. Therefore I make a calculation with days in month.

If the current month is selected I use this formula to calculate day count:

ceil(Makedate(Year(today()), Month(today()),Day(today()))-makedate(Year(today()),Month(today()),1))

If any other month is selected I use this formula to do the same:

ceil(monthend(makedate(Year,Month,1))-makedate(Year,Month,1))

My question is how to combine these when the user selects multiple months?

1 Solution

Accepted Solutions
brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi,

another option:

Num(Today()) - Num(Date)

that means number of days from selected dat to today

View solution in original post

3 Replies
Not applicable
Author

In the load script can you create a table called DateParts, see script below.

Date:

load

today()-recno()+1 as Date

autogenerate(today()-'2005-12-31');

DateParts:

load

Date as Date,

date(monthstart(Date),'MMM-YYYY') as Date_MonthYear,

Year(Date) as Year,

yearname ( Date, 0, 4 ) as FinancialYear,

Month(Date)&' - '&right(year(Date),2) as MonthYear,

Month(Date) as Month,

Day(Date) as Day,

Week(Date) as Week,

Weekday(Date) as WeekDay

resident Date;

drop table Date;

Then create two variables

vMinDate = min(Date)

vMaxDate = max(Date)

Then for reports use the formulas =vMaxDate - vMinDate

This will give the number of days whether you select one month, multiple months or multiple years.

brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi,

another option:

Num(Today()) - Num(Date)

that means number of days from selected dat to today

Not applicable
Author

Thank you! Smile

num(Today()) - num(monthsstart(1,Today())) did the trick.