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

FIFO data join

Hello everybody,

I need an idea how to work this issue.

There are two tables.

Purchase:

DateProductPrice
2015-01-01A1
2015-01-01A1
2015-01-03B2
2015-01-04A3

Sales:

DateProduct
2015-01-02A
2015-01-04B

2015-01-04

A
2015-01-04A

The merged table should look like:

DateProductPrice
2015-01-02A1
2015-01-04B2

2015-01-04

A1
2015-01-04A3

The model should work under FIFO principle.

In case you have any clue how should I reach this result - let me now.

Thank you in advance!

1 Solution

Accepted Solutions
MindaugasBacius
Partner - Specialist III
Partner - Specialist III
Author

For this exact issue the solution appears to be quite simple:

Purchase:

LOAD * INLINE [

    Date, Product, Price

    2015-01-01, A, 1

    2015-01-01, A, 1

    2015-01-03, B, 2

    2015-01-04, A, 3

    2015-01-02, C, 2

];

Sales:

LOAD * INLINE [

    Date, Product

    2015-01-02, A

    2015-01-04, B

    2015-01-04, A

    2015-01-04, A

];

NoConcatenate

tmp:

LOAD *

  ,AutoNumber(RowNo(), Product) as Number

Resident Sales

Order By Product asc, Date asc

;

Left Join (tmp)

LOAD Price

  ,Product

  ,AutoNumber(RowNo(), Product) as Number

Resident Purchase

Order By Product asc, Date asc,

;

DROP Tables Sales, Purchase;

DROP Field Number;

And the outcome is as wanted:

Screenshot_1.jpg

View solution in original post

3 Replies
MK_QSL
MVP
MVP

I think you missed Qty here ! That could also be a part of FIFO.

MindaugasBacius
Partner - Specialist III
Partner - Specialist III
Author

The quantity in every single row is 1 piece.

MindaugasBacius
Partner - Specialist III
Partner - Specialist III
Author

For this exact issue the solution appears to be quite simple:

Purchase:

LOAD * INLINE [

    Date, Product, Price

    2015-01-01, A, 1

    2015-01-01, A, 1

    2015-01-03, B, 2

    2015-01-04, A, 3

    2015-01-02, C, 2

];

Sales:

LOAD * INLINE [

    Date, Product

    2015-01-02, A

    2015-01-04, B

    2015-01-04, A

    2015-01-04, A

];

NoConcatenate

tmp:

LOAD *

  ,AutoNumber(RowNo(), Product) as Number

Resident Sales

Order By Product asc, Date asc

;

Left Join (tmp)

LOAD Price

  ,Product

  ,AutoNumber(RowNo(), Product) as Number

Resident Purchase

Order By Product asc, Date asc,

;

DROP Tables Sales, Purchase;

DROP Field Number;

And the outcome is as wanted:

Screenshot_1.jpg