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

Announcements
FLASH SALE: Save $500! Use code FLASH2026 at checkout until Feb 14th at 11:59PM ET. Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

unique prod id

Hi,

I do have requirement where need to calculate whether prod has been upgraded or downgraded based on three grading systems, the issue is if I prod has been upgraded or downgraded into ratings, i need to count only once.

for example conisder below data

   

    

CompanyProduct IdBusiness dateGrade 1Grade 2Grade 3
MicrosoftA1236/29/2015101010
MicrosoftA1236/28/20159910
MicrosoftA4566/29/2015101010
MicrosoftA4566/28/2015101011
MicrosoftA7896/29/2015131212
MicrosoftA7896/29/2015121212
DukeB1236/28/201591213
DukeB1236/29/201591214
EdisonB4566/28/2015111313
EdisonB7896/29/20159912
EdisonB7896/28/201510109

logic for upgrades: if difference of previous grade-current grade>0, then upgrade

logic for downgrades: if difference of previous grade-current grade<0, then downgrade


as you can see in above example prod A123 of microsoft has been upgraded in both grade 1 and grade 2 and in grade 3 its unchanged,

so, if the product has been upgraded in at least one of grades it should count as only 1 upgrade, so in total Microsoft has two upgraded products A123(in grade 1 and grade2) and A 789, hence count is 2 and for Duke product has been downgraded in grade 3.

o/p table should be

  

CompanyTotal UpgradesTotal Downgrades
Microsoft21
Duke01
Edison11

Can you please let me know the logic for this.  Any help is highly appreciated.

Thanks,

Labels (1)
4 Replies
jagan
Partner - Champion III
Partner - Champion III

Hi,

Try this script

Temp:

LOAD

Company, [Product Id], Date([Business date]) AS [Business date], [Grade 1], [Grade 2], [Grade 3]

INLINE

[   

    Company, Product Id, Business date, Grade 1, Grade 2, Grade 3

    Microsoft, A123, 6/29/2015, 10, 10, 10

    Microsoft, A123, 6/28/2015, 9, 9, 10

    Microsoft, A456, 6/29/2015, 10, 10, 10

    Microsoft, A456, 6/28/2015, 10, 10, 11

    Microsoft, A789, 6/29/2015, 13, 12, 12

    Microsoft, A789, 6/29/2015, 12, 12, 12

    Duke, B123, 6/28/2015, 9, 12, 13

    Duke, B123, 6/29/2015, 9, 12, 14

    Edison, B456, 6/28/2015, 11, 13, 13

    Edison, B789, 6/29/2015, 9, 9, 12

    Edison, B789, 6/28/2015, 10, 10, 9

];

Data:

LOAD

*,

If(Peek(Company) = Company AND Peek([Product Id]) = [Product Id], If([Grade 1] > Peek([Grade 1]), 1, 0) +  If([Grade 2] > Peek([Grade 2]), 1, 0) + If([Grade 3] > Peek([Grade 3]), 1, 0)) AS Upgrade,

If(Peek(Company) = Company AND Peek([Product Id]) = [Product Id], If([Grade 1] < Peek([Grade 1]), 1, 0) +  If([Grade 2] < Peek([Grade 2]), 1, 0) + If([Grade 3] < Peek([Grade 3]), 1, 0)) AS Downgrade

RESIDENT Temp

ORDER BY Company, [Product Id], [Business date];

DROP TABLE Temp;

Now in chart use

Sum(Upgrade) For getting Upgrade count

Sum(Downgrade) For getting Downgrade count

Hope this helps you.

Regards,

Jagan.

qlikviewwizard
Master II
Master II

Hi qkvw1234,

Please follow jagan‌ 's Advise. I used pivot table.

Enclosed the app for your reference.

Capture.JPG

Not applicable
Author

Hi Jagan,

can this be done in UI. ? also if solution if is at script level, i do have multiple dates how do I compare selected date and its previous date. please help..

jagan
Partner - Champion III
Partner - Champion III

Hi,

It is very difficult to do this in front end, you have to do lot of complex expressions.  The best thing is you can do this at script level.