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: 
pascos88
Creator II
Creator II

different formula based on a selection

Hi all, 

there is a way to specify in a formula two different calculation, based on the selection of a field? 

My Column contain number 1,2,3,4,5

If I select 1 I want 2+2

if I select 2 I want the avg 

To better understand: 

If (Column = 1 , 2+2, avg(Column))

 

 

Thanks for any help

 

 

1 Solution

Accepted Solutions
Or
MVP
MVP

A tad hard to try and troubleshoot this particular formula without the actual data...

Does the formula in question return a result if you omit the if() condition?

If it does, there might be an issue with triggering the condition on the same field as your set analysis, though I don't think that's supposed to be the case. You could check by using a different field for the conditional statement.

 

View solution in original post

4 Replies
Or
MVP
MVP

The code you posted should work. What exactly is the problem?

pascos88
Creator II
Creator II
Author

The formula is a bit to complex:

if (DataPoint = 'COG / BoardStructure / BoardType',
avg(
aggr(avg({<DataPoint={"COG / GenderDiversity / Women"}>} ValueChecked), CompanyName)
/
aggr(avg({<DataPoint={"COG / BoardStructure / Board Size"}>} ValueChecked), CompanyName)

)
,0)

 

the results is always 0 even if I select 'COG / BoardStructure / BoardType' in the filter DataPoint

Or
MVP
MVP

A tad hard to try and troubleshoot this particular formula without the actual data...

Does the formula in question return a result if you omit the if() condition?

If it does, there might be an issue with triggering the condition on the same field as your set analysis, though I don't think that's supposed to be the case. You could check by using a different field for the conditional statement.

 

pascos88
Creator II
Creator II
Author

Hi Man, it works. 

was my mistake in the spelling of the text. 

Thanks for your help