Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
muratakkemik
Contributor III
Contributor III

ROW_NUMBER() OVER (PARTITION BY A,B,C ordered by x)

Hi All,

I have Sql query but i need to convert it to QV script. This (ROW_NUMBER() OVER (PARTITION BY A,B,C ordered by x)) function is not working in QV.

Here is my sql script:

; with cte as

(

select ah.artikelid, ae.eankod, s.EanColor, f.EanSize, ae.EanDate,

ROW_NUMBER() OVER (PARTITION BY ah.artikelid, s.EanColor, f.EanSize, ,ae.eankod,

ORDER BY ae.EanDate DESC) AS RN

from artikelhuvud ah inner join artikelean ae on ah.artikellopnr = ae.artikellopnr

inner join  farg f on ae.fargid = f.fargid inner join storlek s on s.storleksid = ae.storleksid

--where ah.artikelid = 223221

order by ah.artikelid,  s.EanColor, f.EanSize, ae.eankod

)

select * from cte

where RN=1

This is my QV script which needs to change;

EanCode:
load ARTIKELLOPNR, ARTIKELID,  EANColor,  EANSize, EANKOD, EANdate
resident EanCodeT
order by ARTIKELLOPNR, ARTIKELID,  EANColor,  EANSize, EANdate DESC;

Drop table EanCodeT;

Data like this:

ARTIKELLOPNR, ARTIKELID,  EANColor,  EANSize, EANKOD, EANdate,     RN   (This was coming with sql but need to be done in qv)

111                         2222               Black          L               12345     10-31-2018          1

111                         2222               Black          L                23232     10-20-2018          2

111                         2222               White          L                45454     10-25-2018          1

111                         2222               White          L                55585     10-20-2018          2

111                         2222               White          M               97474     09-21-2018          1

111                         2222               White          M               58585     09-21-2018          2

nearly Every item, color, size have 2 Ean codes I want to sort them date base and use their last one

Thank you

M

12 Replies
kalyandg
Partner - Creator III
Partner - Creator III

HI,

 

Can you please provide the solution you have tried, which works fast.

Abhi999
Contributor III
Contributor III

I tried this getting error message RN column not available .

tetew89
Contributor II
Contributor II

Hi Andrey, I was trying to replicate this code but for me it is not working. Instead of EANdate I have the column Growth that I want to rank for. I see that you only put the EANDate in the order by clause. If I do the same with growth, it does not work. Do you know why?
Here my script 
load *,
If(Previous(RelativeMonth)=RelativeMonth, Peek(Rank)+1, 1)
as Rank
resident tmp_ca
where SOUnits_PYTD <> 0
order by RelativeMonth, Code3, Year, Month, Growth