qlikviewqliksensesenseset-analysisqlik-expression

Nested Set Analysis in QlikSense


My User_ID has several images and with this piece of code I receive the largest IMAGE_NR .

  max({$<USER_ID = {'8638087'}> } IMAGE_NR) 

Every image number is linked to an IMAGE_ID. How do I get this?

In words:

Give me IMAGE_ID where IMAGE_NR = largest IMAGE_NR of my USER_ID

I tried following that doesn't work:

  sum({$<max({<USER_ID={'8638087'}> } IMAGE_NR)>} IMAGE_ID)

Thank you for any thoughts!


Solution

  • Here is a step-by-step solution.

    You mention that this already brings back the correct IMAGE_NR:

    max({$<USER_ID = {'8638087'}> } IMAGE_NR)
    

    Now you want the IMAGE_ID. The logic is:

    =only({CORRECT_IMAGE_NR_SET_ANALYSIS} IMAGE_ID)
    

    I generally prefer to avoid search mode (double quotes inside element list) and instead use a higher evaluation level on the top calculation, so I would recommend:

    $(=
        'only({<IMAGE_NR={'
        & max({$<USER_ID = {'8638087'}> } IMAGE_NR)
        & '}>} IMAGE_ID)'
    )
    

    This would also provide you a nice preview formula in the formula editor, something like:

    only({<IMAGE_NR={210391287}>} IMAGE_ID)