Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
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
can you post a sample of how your data is structured
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
Can you clarify what you mean?
Can this be written in the function area within dimension or measure? Or it has to be loaded into Qlik Sense?
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
Is mapping used with two different tables? I am only dealing with one table.
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