Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
I am working on creating an "ABC Analysis" in Qlik.
I have a raw table where, on the left side, I have the customers' names (which I’ve removed from the picture).
From left to right, the table includes the following columns:
I have created the following formulas for the raw table:
Now, I would like to calculate the number of customers in each category (A, B, C). For example, in my case, there are 3 customers in category A, 6 in category B, and so on.
I want to perform this calculation in a KPI object, not within a row table object. I have already tried the following formula, but it doesn't work as expected:
COUNT(
AGGR(
IF(
RANGESUM(
ABOVE(
Sum(Sales) / Sum(Total Sales),
0, ROWNO(TOTAL)
) < 0.80,
'A',
CUSTOMER_ID
)
)
Thank you in advance for your help!
I couldn't see a way to easily partition with a group by statement, so worked with each year separately.
Bear with me, it's a bit lengthy, so if anyone has a simpler solution, I'd love to hear about it!
Let me know how you get on!
The ABOVE() function is evaluating the expression at the row above the current in the table. This won't work if you pull it out into a KPI object as there is no "row above" for it to look for.
Can you calculate the Group Assignment in your load script?
Then you could use set analysis to count within a KPI object.
COUNT({$<Group_Assignment={'A'}>}DISTINCT CUSTOMER_ID)
Thank you, Emma!
How would you calculate the group assignment in the load script?
If I calculate the group assignment in my load script, how would Qlik interpret the group assignment when a selection is made on the year? To be more specific, if a customer is assigned to Group A in the load script based on total sales over the years, will it change to Group B if a year is selected in the report, or will it remain fixed to Group A?
You can use GROUP BY and ORDER BY to create the table in the load script in the format that you need.
What behaviour do you want on the front end - do you want it to be dynamic based on year selection or do you want the assignment to be fixed over the full term?
I would like it to be dynamic based on year selection.
So if the user is selecting 2022 or other years, this KPI should be recalculated based on the selections made and so on.
Try this
Sum(Aggr(IF(RANGESUM(ABOVE(Sum(Sales) / Sum(Total Sales), 0, ROWNO(TOTAL))) < 0.80, 1),[Customer ID]))
I couldn't see a way to easily partition with a group by statement, so worked with each year separately.
Bear with me, it's a bit lengthy, so if anyone has a simpler solution, I'd love to hear about it!
Let me know how you get on!
Thank you so much Emma!
I will try and let you know!
I have just applied your script structure to my case.
Your solution is the one I have been looking for!
Thank you Emma!