Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Good day!
In my model i have such table:
Temp:
Load
Chain
Contractor
EAN
YearMonth
Sum
from Sales.qvd (qvd);
For some YearMonths Sum is null.
I need for every EAN, aggregated by Contractor and Chain, where Sum is null, set value from nearest YearMonth.
If there no any nearest YearMonth with sum >0,aggregated by Chain and Contractor, value must be null
Source table:
Chain | Contractor | EAN | YearMonth | Sum |
Auchan | Ашан1 | 456 | 201301 | - |
Auchan | Ашан1 | 456 | 201302 | 45 |
Auchan | Ашан1 | 456 | 201303 | 56 |
Auchan | Ашан1 | 456 | 201304 | - |
Auchan | Ашан1 | 456 | 201305 | - |
Auchan | Ашан1 | 456 | 201306 | 32 |
Auchan | Ашан1 | 456 | 201307 | - |
Auchan | Ашан1 | 456 | 201308 | - |
Auchan | Ашан1 | 456 | 201309 | 543 |
Auchan | Ашан1 | 456 | 201310 | - |
Auchan | Ашан1 | 456 | 201311 | - |
Auchan | Ашан1 | 456 | 201312 | - |
Auchan | Ашан1 | 456 | 201401 | 324 |
Auchan | Ашан1 | 456 | 201402 | 65 |
Auchan | Ашан1 | 456 | 201403 | 342 |
Auchan | Ашан1 | 456 | 201404 | 324 |
Auchan | Ашан1 | 456 | 201405 | 54 |
Auchan | Ашан1 | 456 | 201406 | 324 |
Auchan | Ашан1 | 456 | 201407 | 89 |
Auchan | Ашан1 | 456 | 201408 | - |
Auchan | Ашан1 | 456 | 201409 | - |
Auchan | Ашан1 | 456 | 201410 | - |
Auchan | Ашан1 | 456 | 201411 | - |
Auchan | Ашан1 | 456 | 201412 | - |
Auchan | Ашан1 | 456 | 201501 | 23 |
Auchan | Ашан1 | 456 | 201502 | 24 |
Auchan | Ашан1 | 456 | 201503 | 2342 |
Auchan | Ашан1 | 456 | 201504 | - |
Auchan | Ашан1 | 456 | 201505 | - |
Auchan | Ашан1 | 456 | 201506 | 324 |
Auchan | Ашан1 | 456 | 201507 | - |
Auchan | Ашан2 | 67 | 201301 | - |
Auchan | Ашан2 | 67 | 201302 | - |
Auchan | Ашан2 | 67 | 201303 | - |
Auchan | Ашан2 | 67 | 201304 | - |
Auchan | Ашан2 | 67 | 201305 | - |
Auchan | Ашан2 | 67 | 201306 | 76 |
Auchan | Ашан2 | 67 | 201307 | - |
Auchan | Ашан2 | 67 | 201308 | - |
Auchan | Ашан2 | 67 | 201309 | - |
Auchan | Ашан2 | 67 | 201310 | - |
Auchan | Ашан2 | 67 | 201311 | - |
Auchan | Ашан2 | 67 | 201312 | - |
Auchan | Ашан2 | 67 | 201401 | - |
Auchan | Ашан2 | 67 | 201402 | 56 |
Auchan | Ашан2 | 67 | 201403 | 65 |
Auchan | Ашан2 | 67 | 201404 | 76 |
Auchan | Ашан2 | 67 | 201405 | 343 |
Auchan | Ашан2 | 67 | 201406 | - |
Auchan | Ашан2 | 67 | 201407 | 76 |
Auchan | Ашан2 | 67 | 201408 | - |
Auchan | Ашан2 | 67 | 201409 | - |
Auchan | Ашан2 | 67 | 201410 | - |
Auchan | Ашан2 | 67 | 201411 | - |
Auchan | Ашан2 | 67 | 201412 | - |
Auchan | Ашан2 | 67 | 201501 | 89 |
Auchan | Ашан2 | 67 | 201502 | - |
Auchan | Ашан2 | 67 | 201503 | - |
Auchan | Ашан2 | 67 | 201504 | - |
Auchan | Ашан2 | 67 | 201505 | - |
Auchan | Ашан2 | 67 | 201506 | - |
Auchan | Ашан2 | 67 | 201507 | - |
Necessary table:
Chain | Contractor | EAN | YearMonth | Sum | Necessary sum |
Auchan | Ашан1 | 456 | 201301 | - | - |
Auchan | Ашан1 | 456 | 201302 | 45 | 45 |
Auchan | Ашан1 | 456 | 201303 | 56 | 56 |
Auchan | Ашан1 | 456 | 201304 | - | 56 |
Auchan | Ашан1 | 456 | 201305 | - | 56 |
Auchan | Ашан1 | 456 | 201306 | 32 | 32 |
Auchan | Ашан1 | 456 | 201307 | - | 32 |
Auchan | Ашан1 | 456 | 201308 | - | 32 |
Auchan | Ашан1 | 456 | 201309 | 543 | 543 |
Auchan | Ашан1 | 456 | 201310 | - | 543 |
Auchan | Ашан1 | 456 | 201311 | - | 543 |
Auchan | Ашан1 | 456 | 201312 | - | 543 |
Auchan | Ашан1 | 456 | 201401 | 324 | 324 |
Auchan | Ашан1 | 456 | 201402 | 65 | 65 |
Auchan | Ашан1 | 456 | 201403 | 342 | 342 |
Auchan | Ашан1 | 456 | 201404 | 324 | 342 |
Auchan | Ашан1 | 456 | 201405 | 54 | 54 |
Auchan | Ашан1 | 456 | 201406 | 324 | 324 |
Auchan | Ашан1 | 456 | 201407 | 89 | 89 |
Auchan | Ашан1 | 456 | 201408 | - | 89 |
Auchan | Ашан1 | 456 | 201409 | - | 89 |
Auchan | Ашан1 | 456 | 201410 | - | 89 |
Auchan | Ашан1 | 456 | 201411 | - | 89 |
Auchan | Ашан1 | 456 | 201412 | - | 89 |
Auchan | Ашан1 | 456 | 201501 | 23 | 23 |
Auchan | Ашан1 | 456 | 201502 | 24 | 24 |
Auchan | Ашан1 | 456 | 201503 | 2342 | 2342 |
Auchan | Ашан1 | 456 | 201504 | - | 2342 |
Auchan | Ашан1 | 456 | 201505 | - | 2342 |
Auchan | Ашан1 | 456 | 201506 | 324 | 324 |
Auchan | Ашан1 | 456 | 201507 | - | 324 |
Auchan | Ашан2 | 67 | 201301 | - | - |
Auchan | Ашан2 | 67 | 201302 | - | - |
Auchan | Ашан2 | 67 | 201303 | - | - |
Auchan | Ашан2 | 67 | 201304 | - | - |
Auchan | Ашан2 | 67 | 201305 | - | - |
Auchan | Ашан2 | 67 | 201306 | 76 | 76 |
Auchan | Ашан2 | 67 | 201307 | - | 76 |
Auchan | Ашан2 | 67 | 201308 | - | 76 |
Auchan | Ашан2 | 67 | 201309 | - | 76 |
Auchan | Ашан2 | 67 | 201310 | - | 76 |
Auchan | Ашан2 | 67 | 201311 | - | 76 |
Auchan | Ашан2 | 67 | 201312 | - | 76 |
Auchan | Ашан2 | 67 | 201401 | - | 76 |
Auchan | Ашан2 | 67 | 201402 | 56 | 56 |
Auchan | Ашан2 | 67 | 201403 | 65 | 65 |
Auchan | Ашан2 | 67 | 201404 | 76 | 76 |
Auchan | Ашан2 | 67 | 201405 | 343 | 343 |
Auchan | Ашан2 | 67 | 201406 | - | 343 |
Auchan | Ашан2 | 67 | 201407 | 76 | 76 |
Auchan | Ашан2 | 67 | 201408 | - | 76 |
Auchan | Ашан2 | 67 | 201409 | - | 76 |
Auchan | Ашан2 | 67 | 201410 | - | 76 |
Auchan | Ашан2 | 67 | 201411 | - | 76 |
Auchan | Ашан2 | 67 | 201412 | - | 76 |
Auchan | Ашан2 | 67 | 201501 | 89 | 89 |
Auchan | Ашан2 | 67 | 201502 | - | 89 |
Auchan | Ашан2 | 67 | 201503 | - | 89 |
Auchan | Ашан2 | 67 | 201504 | - | 89 |
Auchan | Ашан2 | 67 | 201505 | - | 89 |
Auchan | Ашан2 | 67 | 201506 | - | 89 |
Auchan | Ашан2 | 67 | 201507 | - | 89 |
Very glad for your help and support.
This?
Temp:
LOAD
*
From Sales.qvd (qvd);
Final:
LOAD *,
If(EAN =Peek('EAN'), If(Len(Trim(Sum)) = 0, Peek('Sum1'), Sum), Sum) as Sum1
Resident Temp
Order By Chain, Contractor, EAN, YearMonth;
DROP Table Temp;
HTH
Best,
Sunny
Temp:
LOAD
AutoNumber(Chain&Contractor&EAN) as Key,
Chain,
Contractor,
EAN,
YearMonth,
Sum
FROM
Sales.qvd (qvd);
Final:
Load
*,
If(Key = Previous(Key) and IsNull(Sum), Peek('NewSum'), Sum) as NewSum
Resident Temp
Order By Key, YearMonth;
Drop Table Temp;
Temp:
load
*
From Sales.qvd (qvd)
;
Final:
LOAD
*,
if(IsNull(Sum) and Previous(EAN)=EAN,Peek(Sum_Final),Sum) as Sum_Final
Resident Temp Order by Chain,Contractor,EAN,YearMonth;
DROP Table Temp;
Chain | Contractor | EAN | YearMonth | Sum_Final |
---|---|---|---|---|
Auchan | Ашан1 | 456 | 201301 | |
Auchan | Ашан1 | 456 | 201302 | 45 |
Auchan | Ашан1 | 456 | 201303 | 56 |
Auchan | Ашан1 | 456 | 201304 | 56 |
Auchan | Ашан1 | 456 | 201305 | 56 |
Auchan | Ашан1 | 456 | 201306 | 32 |
Auchan | Ашан1 | 456 | 201307 | 32 |
Auchan | Ашан1 | 456 | 201308 | 32 |
Auchan | Ашан1 | 456 | 201309 | 543 |
Auchan | Ашан1 | 456 | 201310 | 543 |
Auchan | Ашан1 | 456 | 201311 | 543 |
Auchan | Ашан1 | 456 | 201312 | 543 |
Auchan | Ашан1 | 456 | 201401 | 324 |
Auchan | Ашан1 | 456 | 201402 | 65 |
Auchan | Ашан1 | 456 | 201403 | 342 |
Auchan | Ашан1 | 456 | 201404 | 324 |
Auchan | Ашан1 | 456 | 201405 | 54 |
Auchan | Ашан1 | 456 | 201406 | 324 |
Auchan | Ашан1 | 456 | 201407 | 89 |
Auchan | Ашан1 | 456 | 201408 | 89 |
Auchan | Ашан1 | 456 | 201409 | 89 |
Auchan | Ашан1 | 456 | 201410 | 89 |
Auchan | Ашан1 | 456 | 201411 | 89 |
Auchan | Ашан1 | 456 | 201412 | 89 |
Auchan | Ашан1 | 456 | 201501 | 23 |
Auchan | Ашан1 | 456 | 201502 | 24 |
Auchan | Ашан1 | 456 | 201503 | 2342 |
Auchan | Ашан1 | 456 | 201504 | 2342 |
Auchan | Ашан1 | 456 | 201505 | 2342 |
Auchan | Ашан1 | 456 | 201506 | 324 |
Auchan | Ашан1 | 456 | 201507 | 324 |
This?
Temp:
LOAD
*
From Sales.qvd (qvd);
Final:
LOAD *,
If(EAN =Peek('EAN'), If(Len(Trim(Sum)) = 0, Peek('Sum1'), Sum), Sum) as Sum1
Resident Temp
Order By Chain, Contractor, EAN, YearMonth;
DROP Table Temp;
HTH
Best,
Sunny