Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Only at Qlik Connect! Guest keynote Jesse Cole shares his secrets for daring to be different. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Cumulative count distinct

Hi,

I have a count of distinct customers by month. I need a straight table with month as dimension and # of distinct customers visited till that month.

Basically its a cumulative count distinct function. Please advice how to solve this.

Regards,

Kiran.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Ok, that was a little bit trickier.

I put together a solution. Check out the attached example. I added a field in the script called FirstVisit and use that as a flag set to either 1 or 0. Then I just sum up the FirstVisit flag with full accumulation. I had to do a binary load of your file as I don't have the data sources but you can just add the field in your script after sorting the table accordingly.

(Basically I sort the table on MonthID and CustomerID so that when the CustomerID changes I tag that row with the FirstVisit for later use)

View solution in original post

7 Replies
Not applicable
Author

Are you unable to use the built-in Accumulation functionality? I did a quick test and accumulation seems to work fine on count distinct in a Straight Table.

Otherwise, you may be able to use something like:

count(distinct total if(VisitMonth<=Month and VisitYear<=Year, CustomerID)
You didn't give any information on what fields you were using for the dates and customer, so I guessed.

Not applicable
Author

Thanks for your inputs. I tried accumulation but it didnt work. I attached the sample here for more details.

Regards,

Kiran.

Anonymous
Not applicable
Author

Remove MonthID as a dimension and the go to the Sort tab and set MonthDescr to sort by expression, MonthID, ascending. Then you should be fine.

Not applicable
Author

Did as suggested. The result is the following:

Jan2
Feb3
Mar5
Apr8
May12
Jun16


But the expected result is:

MonthDesc#Customers
Jan2
Feb2
Mar3
Apr3
May4
Jun4


My expression should be number of distinct customers visited till that month.

Regards,

Kiran.

Anonymous
Not applicable
Author

Ok, that was a little bit trickier.

I put together a solution. Check out the attached example. I added a field in the script called FirstVisit and use that as a flag set to either 1 or 0. Then I just sum up the FirstVisit flag with full accumulation. I had to do a binary load of your file as I don't have the data sources but you can just add the field in your script after sorting the table accordingly.

(Basically I sort the table on MonthID and CustomerID so that when the CustomerID changes I tag that row with the FirstVisit for later use)

Not applicable
Author

Wow, thats works great. Thanks a lot Johannes.

Not applicable
Author

This is a great solution. But I have a huge datamodel and its will be difficult to do this. Is that a workaround without a datamodel modification?