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

I have column A with different values and want the average of column B if column A value= X, How can I do that? Thanks!!

I tried 

If (ColumnA='X',Avg(ColumnB),0)

But doesn't give me any data...

8 Replies
ecolomer
Master II
Master II

can you upload an litle example?

varunreddy
Creator III
Creator III

Try this:

avg(If (ColumnA='X',ColumnB))

Cheers!

Not applicable
Author

i believe the reason you are not getting any results is because the syntax says if Column A = X then I want the average of column B, which at this point does not contain anything.

You want to create the values in column B to be the average of column A, only if column A = X

you need something along the line of avg(if(column A='X', column B)) or yopu could also set column b = to a before you implement your original code - then your original code would work

if(column A='X', column B)

If (ColumnA='X',Avg(ColumnB),0

Not applicable
Author

Thanks a lot!!

Not applicable
Author

my recommendation would be to use Varun's solution - it is a little cleaner than the one I suggested

varunreddy
Creator III
Creator III

I am glad that my suggestion helped you

Cheers!

Qrishna
Master
Master

Check Attached.

sunny_talwar

Or this with Set Analysis:

Avg({<ColumnA = {'X'}>} ColumnB)