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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
AmitSah
Contributor II
Contributor II

How to calculate aggregated count using set analysis

Hi Experts,

Below is my sample table structure, where I want to calculate the count of customers which are new and which are existing using some scripting in the front end. like using set analysis and Agg function.

Sales_IDSales_Line_IDStore_IDDate_IDPLU_IDTime_IDQuantityNet_SalesGross_SalesCustomer_ID
89692129201707026728601423.73498.9311043
89692229201707022268601186.44219.5291043
89692329201707022238601254.24299.3621043
8969242920170702239860450.8459.8631043
896925292017070281386011058.471246.3211043
13378712920170702242979172.0369.9951043
133535142016081623996328420300.0181008
106227122201707026668351593.22695.5891043
10622722220170702243835172.0384.461043
88478110201707022498251169.49199.9981043
1169471102017070324912031169.49199.9981043
138761112016052362873711073603.82647848
13876121201605231017371427228.76447848
13876131201605231997371450241.08647848
106499112016052312574711200642.89747848
10649921201605232677471436245.35747848
10649931201605233677471234125.36547848
106499412016052324374718042.8647848
10649951201605233917471407229.03747848
106499612016052357074716333.75247848
106499712016052357174718042.8647848
105030112016052374880711073603.82647848
10503021201605231018071427228.76447848
10503031201605231998071450241.08647848
84151122017070123611251101.69119.9941043
11211513201707022368291101.69119.9941043

 

So, my output should be like:

one measure will give me New Customer Count i.e in the above case it is 1 i.e Customer_ID=1008 who visited only once.

and another measure will give me existing customer count i.e in the above case it is 2 i.e Customer_id (1043 and 47848) who bought items multiple times and on different dates or same dates, for that different Sales_id is generated for those purchase.

I can do that calculation by creating an aggregate table in the data model but I want that calculation to handled in the front end.

for example SQL to aggregate Customer Count:

select a.Customer_ID ,sum(a.customer_count) Cutsomer_Count,sum(a.net_sales) Net_Sales
from(
select count( distinct a.customer_id) customer_count,Store_ID,a.Date_ID,a.Sales_ID,a.Customer_ID,sum(a.net_sales) net_sales
from [dbo].[fact_sales_detailed] a
group by Store_ID,a.Date_ID,a.Sales_ID,a.Customer_ID
) a
group by a.Customer_ID

With this I can easyly get the Cutsomers who are new and existing.

But how can I do the same in front end calculation.

Any Help will be appreciated.

Thanks,

Amit

 

 

Labels (2)
4 Replies
settu_periasamy
Master III
Master III

May be try like

Sum(Aggr(Count(Distinct customer_id),Store_ID,Date_ID,Sales_ID,Customer_ID))

AmitSah
Contributor II
Contributor II
Author

Hi Settu,

I am new to Qlik Sense!

Thanks for the response, Yeah I had tried that out but That is giving me the total distinct customer count. But I want 2 different measure which will be as below:

1. New Customers (Measure) - i.e the count should be <=3

2. Existing customer (Measure) - i.e the count should be >3

How to give condition to filter to get below expression which will give above 2 measures:

Sum( Aggr(Count(distinct Customer_ID_Fact), Store_ID,Date_ID,Customer_ID_Fact,Sales_ID))

because when I am trying to use set analysis using the above expression then it is not validating. 

Could you please help me with the above two-measure expression.

Attached is a Sample QVF file. If you will add customer ID on the Table in Sheet then you can see the customers who's count are more than 3 and who's count are <=3.

Thanks,

Amit

AmitSah
Contributor II
Contributor II
Author

Hi Settu,

I am new to Qlik Sense!

Thanks for the response, Yeah I had tried that out but That is giving me the total distinct customer count. But I want 2 different measure which will be as below:

1. New Customers (Measure) - i.e the count should be <=3

2. Existing customer (Measure) - i.e the count should be >3

How to give condition to filter to get below expression which will give above 2 measures:

Sum( Aggr(Count(distinct Customer_ID_Fact), Store_ID,Date_ID,Customer_ID_Fact,Sales_ID))

because when I am trying to use set analysis using the above expression then it is not validating. 

Could you please help me with the above two-measure expression.

Attached is a Sample QVF file. If you will add customer ID on the Table in Sheet then you can see the customers who's count are more than 3 and who's count are <=3.

Thanks,

Amit

AmitSah
Contributor II
Contributor II
Author

Hi @settu_periasamy 

Did you get a chance to look into this?

Hi, @sunny_talwar  Any Idea on this from your end?

Any help will be appreciated.

Thanks,

Amit