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

How to calculate variable value from variable name saved in table.

Hi ,

I have created two variables 'aa' and 'bb' as follows in my application:

aa   =  sum({$<Name={'b'}>}Value)-sum({$<Name={'a'}>}Value)

bb   =  sum({$<Name={'b'}>}Value)+sum({$<Name={'a'}>}Value)

my table is

LOAD * INLINE [

    Name, Value, Type,TEST_F

    a, 10,,

    b, 25,,

    c, , F,aa

    d,,F,bb

];

In this Table Type ='F' means it is formula and now I want to calculate the values of c and d as variables mentioned aa and bb respectively

so the final output should be

NameValue
a10
b25
c15
d35

in table I used the following expression and it is working fine

if(Type='F',

            if(Name='c',aa,if(Name='d',bb))

,sum(Value))

but Now I do not want to use If condition as there can be more calculations required in future , for the same reason I have used TEST_F value of c and d as formula names.

I want to use something as :

if(Type='F',

            TEST_F

,sum(Value))

Can you please help me out ?

Thanks

Manu

6 Replies
Not applicable
Author

Hi Manu,

Can u try this :

if(Type='F',

    $(=$(=only(TEST_F)))

   ,sum(Value)

  )

Not applicable
Author

No Ashish,

It is not working.

its_anandrjs

Hi,

If you calculate this way what happen by loading the individual values for aa and bb and then load into variable and then load into again in the table by conditions and you have to use the if condition in the variable because SET is not worked in the variables.

Tab1:
LOAD * INLINE [
Name, Value, Type, TEST_F
a, 10
b, 25
c, , F, aa
d, , F, bb
]
;

Values:
LOAD
Sum(if(Name='b',Value)) - Sum(if(Name='a',Value)) as aa,
Sum(if(Name='b',Value)) + Sum(if(Name='a',Value)) as bb
Resident Tab1;

Let aa  = Peek('aa',0,'Values');
Let bb  = Peek('bb',0,'Values');

NoConcatenate
New:
LOAD
Name, Value, Type,
if(Type='F',
if(Name='c','$(aa)',if(Name='d','$(bb)')),Value) as TESTF_Values
Resident Tab1;
DROP Table Tab1;


Output123.PNG

Regards

Anand

Not applicable
Author

Hi,

Can u try this ...

Fill other TEST_F fields with some temporary variable. Declare that variable and assign some dummy value.


In my case inline table is like :


LOAD * INLINE [

    Name, Value, Type,TEST_F

    a, 10,,temp

    b, 25,,temp

    c, , F,aa

    d,,F,bb

];

i have declared variable temp = 0;

now we can use this expression :

=if(Type='F',

    $(=$(=maxString(TEST_F)))

   ,

   sum(Value)

  )

Please try it tell me if it is working ...

Not applicable
Author

Hi Ashish,

I tried this but it is showing one value in all the rows.

Thanks

Manu

Not applicable
Author

Thanks Anand but I want to use without if statement.