Skip to main content
Announcements
Meet the 2024 Qlik Luminaries and Partner Ambassadors! READ ON!
cancel
Showing results for 
Search instead for 
Did you mean: 
agarciaguillen
Contributor II
Contributor II

Qlik Sense - IF inside AVG or SUM

Hi everyone, today i tried to calculate an AVG for a metric like this:

Avg(DISTINCT [Price])

But after that the user send me change, "We need calculate the price based in type of client, if client is type B the metric is Price * 1.21 and if the client isn´t B the metric is Price directly"

If i write separedly:

Avg({<[Client_Type]={'B'}>}DISTINCT [Price]*1.21)

Avg({<[Client_Type]=-{'B'}>}DISTINCT [Price])

The expressions working correctly, but i cant find a way to calculate this average completly.

I tried with:

(Avg({<[Client_Type]={'B'}>}DISTINCT [Price]*1.21)+Avg({<[Client_Type]=-{'B'}>}DISTINCT [Price]))/2

But this expression shows a wrong value.

Is possible put a condicional calculation based in a dimension , inside a AVG or SUM  to show in a metric ?

Thanks in advanced

1 Solution

Accepted Solutions
sunny_talwar

This is one option

Avg(DISTINCT If(Client_Type = 'B', [Price] * 1.21, [Price]))

View solution in original post

2 Replies
sunny_talwar

This is one option

Avg(DISTINCT If(Client_Type = 'B', [Price] * 1.21, [Price]))

agarciaguillen
Contributor II
Contributor II
Author

Really Thanks