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

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

% of Business with variable in formula

Hi,

I want to calculate the % of business each category represents within each customer.

I also determine the sales for This Year and Last Year using an input box and 2 variables vCurrentFinancialYear and vPrevFinancialYear.

To get the % of business I used this formula:

sum({$< FinYear = {$(#vCurrentFinancialYear)} >} (Sales))/ sum({$< FinYear = {$(#vCurrentFinancialYear)} >}total (Sales))

CustomerCustomer OneCustomer TwoTotal
CategorySales This YearSales Last Year% BusinessSales This YearSales Last Year% BusinessSales This YearSales Last Year% Business
Category A$1,744,519$1,935,9287.7%$4,778,266$4,999,58321.1%$6,522,785$6,935,51228.8%
Category B$1,843,478$2,052,1988.1%$5,169,134$5,367,19022.8%$7,012,612$7,419,38831.0%
Category C$1,306,998$1,518,7635.8%$7,783,634$9,669,77534.4%$9,090,633$11,188,53840.2%
Category D$316$7,3640.0%$13,234$34,1320.1%$13,550$41,4960.1%
Total$4,895,312$5,514,25221.6%$17,744,268$20,070,68178.4%$22,639,580$25,584,933100.0%

This works if you want to see the % of business a category represents in the total of all customers but I want to see the total within each customer as the example I mocked up below.

CustomerCustomer OneCustomer TwoTotal
CategorySales This YearSales Last Year% BusinessSales This YearSales Last Year% BusinessSales This YearSales Last Year% Business
Category A$1,744,519$1,935,92835.6%$4,778,266$4,999,58326.9%$6,522,785$6,935,51228.8%
Category B$1,843,478$2,052,19837.7%$5,169,134$5,367,19029.1%$7,012,612$7,419,38831.0%
Category C$1,306,998$1,518,76326.7%$7,783,634$9,669,77543.9%$9,090,633$11,188,53840.2%
Category D$316$7,3640.0%$13,234$34,1320.1%$13,550$41,4960.1%
Total$4,895,312$5,514,252100.0%$17,744,268$20,070,681100.0%$22,639,580$25,584,933100.0%


Does anyone know how to change my formula to do this?

Thanks

David

1 Solution

Accepted Solutions
Not applicable
Author

Very short, use aggr()-function.

View solution in original post

2 Replies
Not applicable
Author

Very short, use aggr()-function.

Not applicable
Author

Hi Thomas,

I haven't used aggr() before so at first I cursed your short post. But humbly I thank you as I had to learn the aggr() function myself which was a good learning experience.

I got it to work as follows if anyone else wants to do this:

sum({$< Year = {$(#vCurrentFinancialYear)} >} (Sales)) / sum(total <Customer> aggr(sum({$< Year = {$(#vCurrentFinancialYear)} >} (Sales)),Customer,Sales))

and I got this report, I now have a % each category makes up of total customers selected (in this case customer one and two) and also the % of business with in customer. (Just to save confusion I used a different period to my last post so thats why the values changed)

CustomerCustomer OneCustomer TwoTotal
CategorySales This YearSales Last Year% of Total Business% of CustSales This YearSales Last Year% of Total Business% of CustSales This YearSales Last Year% of Total Business% of Cust
Category A$1,714,675$1,991,7997.7%35.7%$4,689,368$5,149,43321.0%26.8%$6,404,043$7,141,23128.7%28.7%
Category B$1,808,803$2,111,7318.1%37.6%$5,108,696$5,502,11722.9%29.2%$6,917,499$7,613,84831.0%31.0%
Category C$1,283,231$1,550,9865.8%26.7%$7,673,766$9,856,19334.4%43.9%$8,956,997$11,407,17940.2%40.2%
Category D$316$7,3640.0%0.0%$11,271$34,8810.1%0.1%$11,588$42,2440.1%0.1%
Total$4,807,026$5,661,87921.6%100.0%$17,483,101$20,542,62378.4%100.0%$22,290,127$26,204,503100.0%100.0%

Thanks

David