Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
musketeers
Creator
Creator

How to use variable in IF statement

Hi,

I have a variable in qlikview where I am calculating top 1 country.

Now I am using this variable to display the sales of each state for the country from the variable.

So if the variable name is vCountry.

I am using this statement in Dimension of Pie Chat:

If(country = $(vCountry), State)

But thsi is not working.

I need help in resolving this.

Please help me here.

Thanks

1 Solution

Accepted Solutions
musketeers
Creator
Creator
Author

Hi Avinash,

Thanks for your help.

I realized that I was doing wrong thing. My expression in variable was not working fine. I do not know why. Because when I use that variable in List Box, I was getting one value. But when I used that variable in Text Box, It was not showing any result.

Now I am using the below expression in my variable:

only(if(aggr(Rank(Sum([Sales Amt])),Country)=1,Country))

and I am getting country name in Text Box and List Box both.  (THIS IS FOR TESTING THAT MY VARIABLE IS WORKING FINE)

Now I am using this variable as Sunny has suggested and am getting the result.

I am very thankful to all for your valuable time and suggestion.

View solution in original post

19 Replies
sunny_talwar

What about this:

If(country = vCountry, State)

pooja_sn
Creator
Creator

If(country = $(vCountry), State)

Should work. Check value of your variable. Can you share your qvw file..

musketeers
Creator
Creator
Author

Hi Sunny,

Thanks for your help.

But it is not working.

Thanks

sunny_talwar

How is vCountry gets its value?

martinpohl
Partner - Master
Partner - Master

Hello,

change it into

If(country = '$(vCountry)', State)

Regards

Digvijay_Singh

Hope 'country' spelled correctly

musketeers
Creator
Creator
Author

Hi Sunny, Yes, the variable vCountry is getting value from Country field only. It is dynamic value based on the other filter selection.

Now I want to compare this variable value with the Country Field and get the sum of sales for this country value.

musketeers
Creator
Creator
Author

Hi Martin, when I am using this, I can see that qlikview is replacing '$(vCountry)' with the formula I have written in variable.

Ideally it should calculate the formula and then replace '$(vCountry)' with the result of formula. But this is not happening.

This is the rootcause why this is not working.

sunny_talwar

So if you are already making selection in Country field, I would expect this chart to drill down to only show states for the countries you have selected. Why do you need an if statement here?