Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Accumulating distinct values by week in a barchart

Hi

I need to create a bar chart that counts distinct customers by week cumulatvley.

Here is the expression I have used at present (which works ok when i plot each week individually

({<[Year] = {$(vMaxYear)}>}DISTINCT Customer)

If I select full accumulation it sums the totals from each week but doesn't remove duplicates in the customer number.

I think i probably need to use a rangesum but i'm not sure how to write this.

Any suggestions?

3 Replies
Gysbert_Wassenaar

Perhaps you can get the needed result with an AsOf table where every week is associated with itself and all its previous weeks. That way you should be able to get the accumulated distinct count. See this document for more information: Calculating rolling n-period totals, averages or other aggregations


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks for this, I've tried to add this to my script but it fails to load.

I have over  1,400,000 transactions to calculate against.- woudl this be causing the problem?

I tried the following

AsOfWeek:

load

FWeek as FWeek_AsOf,

FWeek + 1 - IterNo() as FWeek

Resident DEMAND

while IterNo() <= 52;

right join load FWeek Resident DEMAND;

AsOfWeek:

load 'Current' as Type,

FWeek as FWeek_AsOf,

FWeek as FWeek

Resident DEMAND;

Concatenate (AsOfWeek)

load 'Rolling 52' as Type,

FWeek as FWeek_AsOf,

FWeek + 1 - IterNo() as FWeek

Resident DEMAND

while IterNo() <= 52;

right join load FWeek Resident DEMAND; 

Gysbert_Wassenaar

Two things spring to mind:

  1. You probably want to use a load distinct when creating the AsOfWeek table to get the distinct weeks from the DEMAND table. That way you don't start with an AsOfWeeks table with 1,400,000 records.
  2. Right joining the AsOfWeek table with the fact table isn't a good idea since it will explode your fact table.

talk is cheap, supply exceeds demand