Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
waleeed_mahmood
Creator
Creator

Collect similar values in a field and finding avg of individual similar value

I have a similar table in my data load:

Product NumberMPGAB
111aaaaA5212.2
222bbbB6536
3c3c3cA55631
As34s439T5412

ADSWRW22

B643212
FWE544SD9T21456
ADS540-FDA5325

 

So what i want to do is collect like terms in the MPG column and (A-B)/B for each distinct MPG. After finding the Change, i would also like to find individual avg of EACH MPG. so basically divide the change by the number of times an MPG occurs in the original table. 

Calculation Table: (NOTE: Change and AVG(Change) columns don't have to be separated as long as the avg is found)

MPGChangeIndividual AVG(Change)
A5(21-2.2)/2.2 + (56-31)/31

((21-2.2)/2.2 + (56-31)/31 + (32-5)/5)/3

= 4.91

B6

(53-6)/6 + (432-12)/12

((53-6)/6 + (432-12)/12)/2

= 21.412

9T(54-12)/12 + (214-56)/56

((54-12)/12 + (214-56)/56)/2

= 3.16

 

Final Table:

MPGActual Change
A54.91
B621.412
9T3.16

You help is appreciated.

Please let me know if you require any more information.

Labels (3)
1 Solution

Accepted Solutions
sunny_talwar

Try this

Dimension

 

MPG

 

Expression

 

Avg(Aggr(
    (A-B)/B
, [Product Number], [MPG]))

 

View solution in original post

3 Replies
sunny_talwar

Try this

Dimension

 

MPG

 

Expression

 

Avg(Aggr(
    (A-B)/B
, [Product Number], [MPG]))

 

waleeed_mahmood
Creator
Creator
Author

Hi Sunny,

Thank you for your reply. It worked perfectly for my problem. I was wondering if there is a way to convert this into a load script. Since i used your answer in my set expression, i cant use that variable in my load script. is it possible to do the same in a load script?

 

Thank you.

waleeed_mahmood
Creator
Creator
Author

Hi Sunny,

Could you please explain why you have the product number as one of the parameters in the aggr() function?

 

Thanks