Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
nguyenviethung
Contributor III
Contributor III

How to distinct count cumulative with date ranges

Hi experts,

I got data like this table:

Outlet IDDateSalesOrder status
11111/1/201710Approved
11211/1/201720Rejected
11311/1/201730Rejected
11111/1/201790Rejected
11811/1/2017120Approved
11111/4/201740Approved
11311/4/201760Approved
11511/4/2017100Approved
11711/4/2017110Rejected
11911/4/2017130Rejected
11211/5/201750Rejected
11411/5/201770Approved
11511/6/201780Approved
11211/7/201750Approved
11411/7/201770Rejected

I want to count cumulative outlets by date like this:

DateCount distinct Outlet ID with total sales >=45, order status ="approved"Count cumulative Outlet with sales >=45 and order status ="approved"
11/1/201711
11/4/201724
11/5/201715
11/6/201715
11/7/201716
Grand Total66

Can anyone help me the expression for the two ways of counting outlet ID, especially the second count which means Total cumulative outlets with sales >=45 and sales order status must be "approved" only.

Thank you a lot from Vietnam.

22 Replies
nguyenviethung
Contributor III
Contributor III
Author

Thank you, Sunny but it is not really what I meant.

For example, by 11/4/17 we should have 4 outlets that sales >= 45 with status = "approved" like my filter below: (outlet 111 has cumulative sales = 50):

   

Outlet IDDateSalesOrder status
11111/1/201710Approved
11811/1/2017120Approved
11111/4/201740Approved
11311/4/201760Approved
11511/4/2017100Approved

meanwhile your calculation shows 3. Could you please revise it?

sunny_talwar

‌May be this:

Count(DISTINCT {<[Order status] = {‘Approved’}, [Outlet ID] = {“=Sum({<[Order status] = {‘Approved’}>} Sales) >= 45”}>} [Outlet ID])

nguyenviethung
Contributor III
Contributor III
Author

It's still incorrect. I (had to) modify the expression like below and here's the result: Notice that on the first day only 1 outlet with sales > 45, status = approved.

  

AsOfDateCount(
{$<[Outlet ID] = {"=Sum({$<[Order status]={'Approved'}>} Sales) >= 45"},[Order status]={'Approved'}>}
DISTINCT [Outlet ID])
11/1/20172
11/4/20174
11/5/20175
11/6/20175
11/7/20176
sunny_talwar

‌It seemed you were looking at one day at a time. But it seems you are not... I am not home right nowto test it out, but will try it once I am home unless someone else is able to offer help before I do.

nguyenviethung
Contributor III
Contributor III
Author

Your expression:


Count(DISTINCT {<[Order status] = {‘Approved’}, [Outlet ID] = {“=Sum({<[Order status] = {‘Approved’}>} Sales) >= 45”}>} [Outlet ID])


result in this table:

  

AsOfDateCount(DISTINCT {<[Order status] = {‘Approved’}, [Outlet ID] = {"=Sum({<[Order status] = {‘Approved’}>} Sales) >= 45"}>} [Outlet ID])
-0
sunny_talwar

‌Like I said, I am not home... will check once I am home.

nguyenviethung
Contributor III
Contributor III
Author

Hi bro,

Your explanation is quite good, I can catch up with that.

We seem to going on the right direction but It hasnt really solved my case.

Below is my result with your suggested count and two other expressions that I modified from yours and learnt from Sunny Talwar in this topic. His expressions seem to be better but also not really solve. Could you please revise that once again, we neally make it.

 

Datecount({<Status={"Approved"}, Sales={">=45"}>}DISTINCT [Outlet ID])count({<Status={"Approved"}, CumSales={">=45"}>} DISTINCT [Outlet ID])Count(
{$<[Outlet ID] = {"=Sum({$<[Order status]={'Approved'}>} Sales) >= 45"},[Order status]={'Approved'}>}
DISTINCT [Outlet ID])
Count(
{$<[Outlet ID] = {"=Sum({$<[Order status]={'Approved'}>} CumSales) >= 45"},[Order status]={'Approved'}>}
DISTINCT [Outlet ID])
11/1/20172222
11/4/20174433
11/5/20172211
11/6/20171111
11/7/20172211
sunny_talwar

May be try this

Count(DISTINCT {<[Order status] = {'Approved'}>} Aggr(If(Sum({<[Order status] = {'Approved'}>} Sales) >= 45, [Outlet ID]), [Outlet ID], AsOfDate))

Capture.PNG

nguyenviethung
Contributor III
Contributor III
Author

Hi Sunny,

Your solution is correct. Thank you so much.

However, this way could be suitable for low volume data only. I did try with my sales data from Jan-2017 up to now and it takes 1hour and 14 mins to reload data due to AsOfTable; without it, Qlik only takes around 4 mins to reload. My latop is rather good with 8Gb ram and Core i7 chipset. In app sheet, I faced calculation timed out error on running this expression.

Is there any way to improve that?

nguyenviethung
Contributor III
Contributor III
Author

Hi bro,

Although I got correct answer at the below section of this thread by Sunny Talwar, the solution seem to be not applicable for high volume data as it takes too long to reload and calculation timed out error on sheet.

I still hope your direction solve my problem and performance is good. Could you please keep an eye on this and work out the best way?

Thank you so much.