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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
robert_mika
MVP
MVP

Averageif(s)

I know how to Average with one condition but is it possible to add 2 or more?

Labels (1)
1 Solution

Accepted Solutions
swuehl
Champion III
Champion III

There are several possible solutions. For example, create a calculated dimension to create your buckets like

=class(FIELD, 10)

and an expression like

=avg(FIELD)

Or link your FIELD to a table with intervals using Intervalmatch Load prefix.

View solution in original post

8 Replies
maxgro
MVP
MVP

maybe this?

=Avg(if(match(Product,'a','b','c') and ProductType <>'B' or ProductType like '*C*', Expression1))

swuehl
Champion III
Champion III

Not sure if I understood correctly, maybe something like this?

=avg(if( (FIELD1 >= 10 and FIELD2 = 'A') or FIELD3 <= 10, VALUE))

jvitantonio
Specialist III
Specialist III

Hi Robert,

I would avoid using IF's and use Set Analysis instead.

Example:

=Avg({< MyField = {">=10<250"} >} MyField)

The above would be the same as Avg(If(MyField >=10 and MyField <250, MyField)) but would perform better.

Best

JV

robert_mika
MVP
MVP
Author

Thank you all for answer but I may need something else

Let say I have table

Cost

10

10

20

21

Now I need average

<=10

and

>10 and <21

so the answers will be

10

20

I do not want to hard coded any of the numbers

I would like to point to another column or object

let say

Low High Result

0     10    10

10   20    20

swuehl
Champion III
Champion III

There are several possible solutions. For example, create a calculated dimension to create your buckets like

=class(FIELD, 10)

and an expression like

=avg(FIELD)

Or link your FIELD to a table with intervals using Intervalmatch Load prefix.

robert_mika
MVP
MVP
Author

swuehl

This is it

Thank you.

Is it possible to add 3 criteria:

Let say

Between

10 and 20 and when another field is let say A?

swuehl
Champion III
Champion III

I think you can add that condition in the avg() function:

=avg(if(AnotherField = 'A', FIELD))

or using set analysis:

=avg({<AnotherField = {'A'}>}  FIELD)

robert_mika
MVP
MVP
Author


Thnak you but is this posiible to use another column instead of hard coded 'A'.

I assume that this may  need to add another calculated dimension?

Or am I worng?