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: 
Not applicable

Average new field on the Script

Hi,

I want to create a new field called "AvgPlace" by calculating the average of the values for the places. My data is like this:

Place   Store   Value

A          x          3

A          y          2

B          z          2

B          v          4

B          w         3

and I want a new table like this

Place    AvgPlace

A            2.5

B            3

I want to do it on the Script, but it just keeo telling me "Invalid Expression"

1 Solution

Accepted Solutions
Gabriel
Partner - Specialist III
Partner - Specialist III

Hi,

Try this

Data:

load * Inline [

Place ,  Store,   Value
A ,         x  ,        3
A ,         y,          2
B ,         z ,         2
B ,         v,          4
B,          w,         3
]
;


NoConcatenate
Data2:
LOAD
Place  //If you don't want the tables to join then rename this field
,Sum(Value) / Count(Place) AS AvgValue
Resident Data
Group BY
Place;

View solution in original post

4 Replies
swuehl
MVP
MVP

LOAD

     Place,

     avg( Value) as AvgPlace

RESIDENT YourTable

GROUP BY Place;

Gabriel
Partner - Specialist III
Partner - Specialist III

Hi,

Try this

Data:

load * Inline [

Place ,  Store,   Value
A ,         x  ,        3
A ,         y,          2
B ,         z ,         2
B ,         v,          4
B,          w,         3
]
;


NoConcatenate
Data2:
LOAD
Place  //If you don't want the tables to join then rename this field
,Sum(Value) / Count(Place) AS AvgValue
Resident Data
Group BY
Place;

Not applicable
Author

You guys are amazing! Thank youu

Not applicable
Author

Thank youuuu