Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

One formula, mathematical operation on one dimensional value, then add together?

Hello community,

I am struggling with even figuring out what to use for a search string when researching this topic. Basically, I have a situation where I need to perform a multiplication against each dimensional value then add each resulting value together, finally dividing by the sum of another set of values. I am not able to see a clear path through to this but know it should work. Your guidance is greatly appreciated.

Let me illustrate...(a weighted average)...

Formula: ((P1*W1) + (P2*W2)) / (W1+W2)

Let's put some real values behind this...

GroupGenderPopulationWeight
1Male452
1Female231
2Male195
2Female410

(SUM(Population)*SUM(Weight)) / SUM(Weight)

Does not give the correct value because it will add all of the populations and add all the weights finally multiplying the two values before dividing by the weights (which would mathematically negate the multiplication anyhow).

What we need to do is:

((45*2) + (23*1) + (19*5) + (4*10)) / (2+1+5+10)

    = ((90)+(23)+(95)+(40)) / (18)

    = (248) / (18)

    = 13.78

The total weight averages of all genders.

Furthermore, I then need the same formula to work if I create a chart object with the dimension Gender and the total weighted average (irrespective of Group):

Male weighted: ((45*2)+(19*5)) / (2+5) = 26.43

Female weighted: ((23*1)+(4*10)) / (1+10) = 5.73

GenderWeighted Average
Male26.43
Female5.73

Finally, you would be able to use the same formula is showing the Group and total weighted average (irrespective of the Gender):

Group 1 weighted: ((45*2) + (23*1)) / (2+1) = 37.67

Group 2 weighted: ((19*5) + (4*10)) / (5+10) = 9.0

GroupWeighted Average
137.67
29.0

And you get the idea. One formula, any slice as long as we use the Population and the Weight in the formula.

Mike

Message was edited by: Michael Forte - Corrected a typo

13 Replies
Anonymous
Not applicable
Author

I don't need to have it collapsed. The table is locked. The data set has multiple KPIs as rows with each fitting in a category and each having a different formula. There is a specific sort applied to the order of the KPIs as well using a separate dimension between the category and the KPI. For ease of maintenance the developer uses one expression for actual leveraging a Pick(Match()) combo to select the correct formula. The table as three dimensions across the top. When I use this expression standalone it works but if I use it in the table it does not. I'm thinking of adding the first level aggregation to the script so I only have to add and divide. This is driving me nuts and the application really needs to be rewritten.

Maybe a data set like this...

MonthAreaKPICustomerCategoryGroupScenarioValue

Jan

MarketingPopulationAMale1Actual45
JanMarketingPopulationAMale2Actual19
FebMarketingPopulationAMale1Actual10
FebMarketingPopulationBMale2Actual30
JanMarketingPopulationAFemale1Actual23
JanMarketingPopulationBFemale2Actual4
FebMarketingPopulationBFemale1Actual20
FebMarketingPopulationBFemale2Actual8
JanMarketingWeightAMale1Actual2
JanMarketingWeightAMale2Actual5
JanMarketingWeightAFemale1Actual1
JanMarketingWeightBFemale2Actual10
FebMarketingWeightAMale1Actual4
FebMarketingWeightBMale2Actual3
FebMarketingWeightBFemale1Actual19
FebMarketingWeightBFemale2Actual7
JanDesignVolumeAMale2Actual100
JanSafetySalesAMale2Actual0.54
FebDesignVolumeAMale2Actual1040
MarDesignVolumeAMale2Plan109
FebSafetySalesAMale2Actual100.54
JanDesignLossesBFemale1Actual-503.00
JanMarketingLossesBFemale1Actual-605.90
JanMarketingLossesB--CommentUnknown
JanMarketingPopulationA--CommentMale customers played a larger role in our monthly metrics.
JanDesignLossesB--CommentLosses were higher than normal

  

AB
1212
MaleFemaleMaleFemaleMaleFemaleMaleFemale
MarketingPopulationweighted
Lossessum
DesignVolumestraight avg
Lossessum
SafetySalessum
sunny_talwar

It might help if you can share the application where you have the chart where we can see what you have and what you are trying to accomplish... I can only give you a solution for something you provide... if we are going to incrementally add things, we might never finish this discussion. So, I request you to provide a somewhat complete sample app and point out what isn't working for you.

Best,

Sunny

Anonymous
Not applicable
Author

I understand and agree Sunny. I cannot share the application due the sensitivity of the data and design. I will need some time to come up with a different set of data for which I can replicate the issue. Honestly, I am pushing for the entire design to change. I truly appreciate your remarkable insight and assistance.

sunny_talwar

Sounds good... in the mean time, if confidentiality and sensitivity of the data is the only concern that you have, please spend some time to look at this

Preparing examples for Upload - Reduction and Data Scrambling

This may help you address those concerns..

Best,

Sunny