Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
alec1982
Specialist II
Specialist II

use variable in expression

hi all,

I have a table with sales amounts of each department..the department names are the headers and the sales amounts are the rows..

Department 1     Department2     Department3

1000                    2000                    2200

I have created an inline table with the names of the departments and created a variable to have get selected value of the department name.

trying to use a variable in expression to switch the column name

sum([$(varDepartment)]

so when I change my selection I get the selected department sales... but it is not working..

any idea..

1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi

you can use this

=$(='sum([' & $(varDepartment) & '])')

this should do the trick

but if i where you i will do a crosstable load on the original table

to get the table to this structure:

DivisionName,Sales

Division1,1000

Divison2,2000

Divison3 ,2200

then use a list box of the division field for selecting specific division 

View solution in original post

6 Replies
sunny_talwar

See if the attached helps.

Best,

Sunny

jagan
Partner - Champion III
Partner - Champion III

HI,

Try like this

Variable Declaration:

vDepartment = Depatment 1


Expression =Sum([$(=vDepartment)])

Hope this helps you.

Regards,

Jagan.

lironbaram
Partner - Master III
Partner - Master III

hi

you can use this

=$(='sum([' & $(varDepartment) & '])')

this should do the trick

but if i where you i will do a crosstable load on the original table

to get the table to this structure:

DivisionName,Sales

Division1,1000

Divison2,2000

Divison3 ,2200

then use a list box of the division field for selecting specific division 

alec1982
Specialist II
Specialist II
Author

your samples work exactly as i need but it is not working on my data within QlikSense....

alec1982
Specialist II
Specialist II
Author

thank you.. this worked for me... I cannot use cross table here as the data is used somewhere else too.. so I was looking for a quick solution..

thank you for your help!

sunny_talwar

I thought you wanted to do this in QlikView because you posted this on QlikView forum. Not sure how Qlik Sense works for the same.