Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Counting valid subscriptions on months last day

Hi,

I have linked subscription data to mastercalendar, and I'm trying to achieve something like this:

Dim 1 : MasterCalendar.Year

Dim 2 : MasterCalendar.Month

Expr 1 : SUM( Subs.Sales )

Expr 2 : Count( Distinct Subs.Id )

YearMonthSalesActive subscriptions
2013125534
2013234336
2013385645

The problem is, that when the business folk talk about "number of subscriptions", they mean the amount of active subscriptions on the last day of the month in question (ie. do not count the subscriptions that ended before the last day of the month).

How do I get count of only the last day instead of the count of the whole month?

I've tried using set analysis

Count( {MasterCalendar.Date = {$(=...get last day of month when year = dim 1 and month = dim 2...)}} distinct Subs.Id)

But as far as I can tell, you can't use dimensions with the set analysis.

How should I solve this?

3 Replies
Not applicable
Author

Hi,

Use master calender date for calulation of last day of month.

e.g. =MonthEnd(if(Year='' and Month='',Date))


Not applicable
Author

Try the following work around

In the script, create one more table like below

MonthlySubscription:

Load Year,

     Month,

     Max(Date) as LastDay

Resident MasterCalendar GroupBy Year, Month

Left Join (MonthlySubscription) Load

     Date as LastDay,

     Count(Distinct SubsID) as SubscriptionCount

Resident FACT

now in your expression you can use Sum(SubscriptionCount)

preminqlik
Specialist II
Specialist II

hi mika,

try this


Count( {<Year={$(=Max(Year)},Month={$(=Max(month)},week={$(=max(week)},Day={$(=max(Day-1)}>}Distinct Subs.Id )