Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikviewaf
Creator
Creator

Amount field - based on condition

Hi Guys,

i have a table with following values:

  • Company
  • Currency
  • Amount X
  • Amount Y

Basically i would like to create another field based on the following condition:

If Company= 00010 and Currency = USD -> "Amount field"(new one) should be AMOUNT X

If Company= 00010 and Currency <> USD -> "Amount field"(new one) should be AMOUNT Y

If Company= 00030 and Currency = EUR -> "Amount field"(new one) should be AMOUNT Y

If Company= 00030 and Currency <> EUR -> "Amount field"(new one) should be AMOUNT X


how i can build this new calculated field?

Thank you,

1 Solution

Accepted Solutions
kamal_sanguri
Specialist
Specialist

In Script :

If (Company= '00010' and Currency = 'USD',[AMOUNT X],

     If(Company= '00010' and Currency <> 'USD', [AMOUNT Y],

          If(Company= '00030' and Currency = 'EUR', [AMOUNT Y],

               If(Company= '00030' and Currency <> 'EUR',[AMOUNT X])))) as [Amount field]

View solution in original post

5 Replies
kamal_sanguri
Specialist
Specialist

In Script :

If (Company= '00010' and Currency = 'USD',[AMOUNT X],

     If(Company= '00010' and Currency <> 'USD', [AMOUNT Y],

          If(Company= '00030' and Currency = 'EUR', [AMOUNT Y],

               If(Company= '00030' and Currency <> 'EUR',[AMOUNT X])))) as [Amount field]

passionate
Specialist
Specialist

Hi Antonio,

I would suggest create a flag in the table based on condition and then use the flag value in charts or calculation.

  

Requirement:

CompanyCurrencyFlagXY
00010USDX21001200
00010EURY2002150
00030USDX23001200
00030EURY15004586

Straight Table:

Dimension1: Company

Dimension2: Currency

Expression:

Pick(Match(Flag,'X','Y'),Sum(X),Sum(Y))

Chart will look like:

Company Currency Pick(Match(Flag,'X','Y'),Sum(X),Sum(Y))
10EUR2150
10USD2100
30EUR4586
30USD2300

Regards,

Pankaj

qlikviewaf
Creator
Creator
Author

I guess that for performance point of view is better.

How can i create the flag?

passionate
Specialist
Specialist

Hi Antonio,

Flag can be created by similar approach which kamal used in script:

If (Company= '00010' and Currency = 'USD',[AMOUNT X],

     If(Company= '00010' and Currency <> 'USD', [AMOUNT Y],

          If(Company= '00030' and Currency = 'EUR', [AMOUNT Y],

               If(Company= '00030' and Currency <> 'EUR',[AMOUNT X])))) as [Amount field]

I would suggest use Pick(Match()) instead of multiple If's For better performance

Creating flag will help if this scenario repeats on your dashboard.

Regards,

Pankaj

kamal_sanguri
Specialist
Specialist

Hi Pankaj,

I don't get the point of creating Flag first in Script and then using an expression in UI to get the value calculated. When everything can be done at the script level using the same script to create Flag and nothing is required at UI.

Am I missing here something???