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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
musketeers
Creator
Creator

Need help in set analysis expression

Hi, I have below data as  a inline table load statement:

PROD_DATA:
Load Inline [Product,Returned/NotReturned,Reason,Quantity
P1, R, R1, 10
P2, R, R2, 20
P3, R, R3, 40
P4, R, R4, 30
P1, NR, , 50
P2, NR, , 40
P3, NR, , 60

P4, NR, , 70
]

ProductReturned/NotReturnedReasonQuantity
P1RR110
P2RR220
P3RR340
P4RR430
P1NR 50
P2NR 40
P3NR 60
P4NR 70
P1RR250
P2RR520
P3RR140
P4RR230

From this data we have filter on Reason column. If user select a Reason say R1. We have two products P1 and P3 which are returned for reason R1. For other products the return reason is not R1. so the output is like below:

R/NRProductCount
RP110
NRP1100
RP20
NRP280
RP340
NRP3100
RP40
NRP4130

 

For R1 reason product P1 has 10 returns. Hence 10 shown. for Not returned status, we should display total number of products minus (-) total return for selected reason. Hence 100 shown for product P1 and status Not returned. For product P2 there is no return for Reason R1 hence 0 shown and for Not Return status 80 as total count of P2 ie 80 minue (-) total return for reason R1 which is 0.

I have written ste analysis for return count ie sum({<Returned/NotReturned = {'R'}>}Quantity)

I am stuck with the Not Return count expression for this given requirement. I have written:

sum({<Returned/NotReturned = {'NR'},Reason>}Quantity)

This is wrong as this will count only those with status Not Returned. But what about those which are returned and not in selected reason. Those also I need to display in Not Return.

I need your expert advise how to acheive this requirement.

Labels (2)
1 Solution

Accepted Solutions
Sayed_Mannan
Creator II
Creator II

Hi, I’ve made a few adjustments to the script. You can now use this single expression to get exactly the output you're looking for:

here is the modified script:

=If([Returned/NotReturned] = 'R',
    Sum({<Reason = {'R1'}>} Quantity),
    If([Returned/NotReturned] = 'NR',
        Sum({<Reason -= {'R1'}>} TOTAL <Product> Quantity)
    )
)

 

here is the output that I am getting:-

Sayed_Mannan_0-1748854394576.png

 

Let me know if this works for you or if you'd like any further tweaks!

View solution in original post

5 Replies
Sayed_Mannan
Creator II
Creator II

Thanks for the detailed explanation! You are very close to the solution.

lets break it down:-

The correct Returned Quantity Expressions should be :

Sum({<Returned/NotReturned = {'R'}, Reason = {'R1'}>} Quantity

The correct Not Returned Expression should be: 


Sum({
    <Returned/NotReturned = {'NR'}>
    +
    <Returned/NotReturned = {'R'}, Reason -= {'R1'}>
} Quantity

If you want to make it dynamic based on user selection, you need to use the P() function to get selected values:-

Sum({
    <Returned/NotReturned = {'NR'}>
    +
    <Returned/NotReturned = {'R'}, Reason -= P(Reason)>
} Quantity)

This way, it will always subtract the selected Reason(s) from the 'R' rows and include the rest.

I hope this helps.

Cheers,
Sayed Mannan Ahmad

musketeers
Creator
Creator
Author

Hi Sayed, Thanks verymuch for your help. I tried this option but the issue is that the part of setanalysis :

 <Returned/NotReturned = {'R'}, Reason -= P(Reason)>

is returning 0 for NR rows and only return data for NR status.

rafaelencinas
Partner - Creator II
Partner - Creator II

Hi !

Lets check each point:

1 - Total Produtcs ( Return and Not Returned ) - ignore the Reason

Sum({<Reason=>}Quantity)

- When you select a Reason, will count / sum all produts

2 - Total Produtcs Returned

Sum({<Reason=,[Returned/NotReturned]={'R'}>}Quantity)

3 - Total Products Not Returned

Sum({<Reason=,[Returned/NotReturned]={'NR'}>}Quantity)

 

In your cenario, if you start selecting the Reason to analyze produtcs, its better to ignore the reasons. 

 

Bye!

 

 

Senior Qlik Architect
Cobra, Stallone, "You're a problem and I'm the solution"
musketeers
Creator
Creator
Author

Hi Stallone, Thanks for your suggestion. My actual problem is the table chart visual which I need to create

R/NRProductCount
RP110
NRP1100
RP20
NRP280
RP340
NRP3100
RP40
NRP4130

 

Here in the Returned rows, the set analysis

Sum({<Returned/NotReturned = {'R'}, Reason = {'R1'}>} Quantity)

shows the correct amount.

The problem is in Not Returned rows. When I try to calculate those returned product with reason other than R1, it is not allowing me to calculate for Not Returned rows.

Any help will be much appreciated.

Thanks

 

Sayed_Mannan
Creator II
Creator II

Hi, I’ve made a few adjustments to the script. You can now use this single expression to get exactly the output you're looking for:

here is the modified script:

=If([Returned/NotReturned] = 'R',
    Sum({<Reason = {'R1'}>} Quantity),
    If([Returned/NotReturned] = 'NR',
        Sum({<Reason -= {'R1'}>} TOTAL <Product> Quantity)
    )
)

 

here is the output that I am getting:-

Sayed_Mannan_0-1748854394576.png

 

Let me know if this works for you or if you'd like any further tweaks!