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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Compare variables using IF statement in Set Analysis

I'm trying to get the code below to work.  It works fine when using the line that is commented out -

if( (Business_GF_Old<>Business_GF) and (Report_Grouping_Old<>Report_Grouping),Constant,0)

However, I need these values to change dynamically with the values for vBus_Dim_Name_Old and vBus_Dim_Name.  I've tried single quotes, double quotes, but can't get it to work.  Any help is greatly appreciated.  Thanks.

Sum (

{<

Hires={0},Terms={0}

>}if( ($(vBus_Dim_Name_Old) = $(vBus_Dim_Name)) and (Report_Grouping_Old<>Report_Grouping),Constant,0)

//>}if( (Business_GF_Old<>Business_GF) and (Report_Grouping_Old<>Report_Grouping),Constant,0)

)

10 Replies
Not applicable
Author

Hi Arthil

I suggest you to check the Variables. Check whether the variables are returing you the correct value.

If so, then i may ask for sample file.

Regards,

Srini.

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

I don't know what you tried but single quotes should work, like this

Sum ({<Hires={0}, Terms={0}>}

if( '$(vBus_Dim_Name_Old)' = '$(vBus_Dim_Name)' and Report_Grouping_Old <> Report_Grouping,

Constant, 0))

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Jonathan - I tried single quotes, exactly like you have, but it didn't work.  Any other ideas?  Thanks.

Not applicable
Author

Srini - what is the best way to check the values of my variables.  Under Settings >> Variable Overview, I see the values for my variables.

jonathandienst
Partner - Champion III
Partner - Champion III

Then I suggest that you post your application (or some subset of it), so we can examine why. That statement is syntactically correct, so I suspect the problem may be somehow in the data (one or more embedded quotes, for example).

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Hi Arthil,

I tried with sample data and this function worked well.

Sum(IF($(vDim_Selected) <> $(vOldDim_Selected),sales))

     vDim_Selected - Definition is "=GetFieldSelections(Fields)"

     vOldDim_Selected - definition is "=GetFieldSelections(Old_Fields)"

Regards,

Srini.

Not applicable
Author

Srini - my variables are being populated via input boxes.  Do you think that would make a difference?

Not applicable
Author

Hi arthil21,

variables can be populated by any means.. input boxes, fields, etc

the code by srinivasa works fine.

i believe the issue lies in the data.. maybe not proper cleansing or different format(uppercase/lowercase/mixedcase/spaces) might lead to the condition getting unfullfiled..

i advise you to check the data for correction first.

Cheers,

Abhinava

Not applicable
Author

All:  thanks everyone for your help.  The code actually works as I originally wrote it.  The problem was that my evaluation for this piece should have been "not equal to" (<>):

$(vBus_Dim_Name_Old) = $(vBus_Dim_Name)) should be $(vBus_Dim_Name_Old) <> $(vBus_Dim_Name))

I also found that with or without single quotes didn't seem to make a difference.  Does anyone know which one is syntactically correct?

$(vBus_Dim_Name_Old) = $(vBus_Dim_Name))

or

'$(vBus_Dim_Name_Old)' = '$(vBus_Dim_Name)')