Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
sona_sa
Creator II
Creator II

Expression Code Improvement

Hi Team,

Below is a code : I want to modify the code in simple way, Can any one help me on this :

if(GetFieldSelections(Options1)='Millions', sum({<account={'EX'},Date={'$(=vTime1)'}>}a_expenses)/1000000, sum({<account={'EX'},Date={'$(=vTime1)'}>}a_expenses))),

if(GetFieldSelections(Options1)='Millions', if(GetFieldSelections(Options2)='No', sum({<account={'EX'},Date={'$(=vTime1)'}>}non_pti)/1000000, sum({<account={'EX'},Date={'$(=vTime1)'}>}non _pti_cc)/1000000),

if(GetFieldSelections(Options2)='No', sum({<account={'EX'},Date={'$(=vTime1)'}>}non), sum({<account={'EXPSENSE_TYPE'},Date={'$(=vTime1)'}>}non_ex_cc))),

if(GetFieldSelections(Options2)='No', sum({<account = {'EX'},Date={'$(=vTime1)'}>}t_p), sum({<account = {'EX'},Date={'$(=vTime1)'}>}t_p_ex_cc))),

If (GetFieldSelections(Options1)='Millions', Sum({<account={'EX'},Date={'$(=vTime1)'}>}o_expenses)/1000000,  Sum({<account={'EX'},Date={'$(=vTime1)'}>}o_expenses))

Thanks

AK

7 Replies
sona_sa
Creator II
Creator II
Author

Can anyone help me on this. Or I should to close this post ? Reason after that again I have to add more condition on the same. Like If Amount is >1M, Then Show me Amount.

Regards,

AK

Vegar
MVP
MVP

If you declare the Options1 values with dual values you won't need the
If (GetFieldSelections(Options1)...

Load dual(Text, Value) as Options1
Inline [
Text, Value
Million, 1000000
Thousand, 1000
Regular, 1];

Then you can write like this
[...] sum({<account={'EX'},Date={'$(=vTime1)'}>}a_expenses)/only(Options1), [...]
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

It's times like this I'm disappointed we can only give a single "like" @Vegar . I would give you triple likes for this response if I could 🙂

-Rob

sona_sa
Creator II
Creator II
Author

Hi Vegar,

Thanks for reply. But here in the script:

Options1:
Load * Inline [
Options1
Millions
Full value];

Options2:
Load * Inline [
Options2
Yes
No];

Options3:
Load * Inline [
Options3
‘1M$’
‘2M$’
‘3M$’];

Expression :--> if(GetFieldSelections(Options1)='Millions',sum({<account={'EX'},Date={'$(=vTime1)'}>}a_expenses)/1000000, sum({<account={'EX'},Date={'$(=vTime1)'}>}a_expenses))),

if(GetFieldSelections(Options1)='Millions', if(GetFieldSelections(Options2)='No', sum({<account={'EX'},Date={'$(=vTime1)'}>}non_pti)/1000000, sum({<account={'EX'},Date={'$(=vTime1)'}>}non _pti_cc)/1000000)

Now I have to use options3 where user can select 1M$, so > 1M$ records should to select, If User Select 2M$ then >2M$ records should to select or if 3M$ then >3M$ records.

So Can anyone help me on this.

Lots of advance thanks.

Regards,

AK

Vegar
MVP
MVP

Before you start to expand your expression with a third clause, you need to make sure your current expression is correct.

You have paranthesis issues with your expression. (your first IF closes at the first paranthesis on line 11 in my picture. )

image.png

Vegar
MVP
MVP

As I mentioned earlies, if you adjust your first table to this: 

Options1:
Load dual(txt,value) as Options1 Inline [
txt, value
Millions, 1000000
Full value, 1];

then you could dimplify your current expression like this. I only applied it on the first IF in my example

/* The part inside this comment can be replaced by the expression below.
If(
   GetFieldSelections(Options1)='Millions',
   sum({<
	account={'EX'},
	Date={'$(=vTime1)'}
	>}a_expenses)/1000000, 
   sum({
	<account={'EX'},
	Date={'$(=vTime1)'}
	>}a_expenses)
 )
 */
 sum({<
   account={'EX'},
   Date={'$(=vTime1)'}
   >}a_expenses)/only(Options1)

 

sona_sa
Creator II
Creator II
Author

Hi Vegar, Can you make it for 2nd and 3rd Options as per my requirements.

It will be very helpful For me. But in there option = Not 

Regards,

AK