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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
breezy1234
Contributor
Contributor

IF statement or CASE

Hello, looking for help on my IF statement to be used as a Measure/Dimension. I'm a beginner in coding but know some basics. I mainly code with SQL. 

I'm creating an IF statement that can replace a product with another product that can be used in place for it, keep in mind I have 3 main products with 3-6 replacements for each main product.

Ex 1: Product A (main product) but is at 0 in inventory so Product A.2 can fill in because it has an inventory of 5.

Ex 2: Product C (main product) is at 0 in inventory so Product C.2 can replace but it is at 0 also. Next product is C.3 and that has an inventory of 2. So, will use Product C.3 to replace Product C.

What would be better, IF or CASE statement? 

Thanks!

 

 

 

 

Labels (4)
1 Solution

Accepted Solutions
marcus_sommer

Yes, it means to have at least two tables - the mapping table and another one in which per applymap() or mapsubstring() the mapping-call is placed. That's intended and not a detour else a very practically approach to load the appropriate mapping-information and/or to define them (if none exists you need to define it in any case - if it's rather ugly done within if-loops or more readable within an inline-table - the work itself must be done).

- Marcus

View solution in original post

7 Replies
vinieme12
Champion III
Champion III

can you post a sample of how your data is structured

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
marcus_sommer

Within the most scenarios it's not necessary or beneficially to use if-loops or case-statements to replace values or to categorize them. Quite common for such tasks is the use of a Mapping ‒ Logic

- Marcus

breezy1234
Contributor
Contributor
Author

Can you clarify what you mean?

breezy1234
Contributor
Contributor
Author

Can this be written in the function area within dimension or measure? Or it has to be loaded into Qlik Sense?

marcus_sommer

Mapping could be only used within the script whereas an if-logic could be also applied within the UI. Ideally all logic is done within the script because it's much easier, more flexible and ensured the best UI performance and usability.

- Marcus

breezy1234
Contributor
Contributor
Author

Is mapping used with two different tables? I am only dealing with one table.

marcus_sommer

Yes, it means to have at least two tables - the mapping table and another one in which per applymap() or mapsubstring() the mapping-call is placed. That's intended and not a detour else a very practically approach to load the appropriate mapping-information and/or to define them (if none exists you need to define it in any case - if it's rather ugly done within if-loops or more readable within an inline-table - the work itself must be done).

- Marcus