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: 
bilionut
Contributor III
Contributor III

grup different table by date and item

HI,

The data is structured as follows

Orders:
LOAD * INLINE [
    OrderID, OrderDate
    101, 1/2/2014
    102, 1/2/2014
    103, 3/3/2014
];
OrdersDetails:
//Inner Join (Orders)
LOAD * INLINE [
    OrderID, ItemID, OrderQty
    101,    15,        111
    101,    16,        250   
    102,    17,        333
    103,    15,        100
];

MfgOrders:
LOAD * INLINE [
    MfgID, MfgOrderDate
    5101, 1/2/2014
    5102, 2/2/2014
    5103, 3/3/2014
];
//Inner Join (MfgOrders)
MfgOrdersDetails:
LOAD * INLINE [
    MfgID, ItemID, MfgOrderQty
    5101,    15,        222
    5101,    16,        300   
    5102,    17,        333
    5103,    18,        250   
];

//Inner Join (Orders)
Items:
Load * INLINE [
    ItemID,    Item
    15,    Aaaa
    16,    Bbbb
    17, Cccc
    18,    Dddd   
];

I try to make a table or a pivot table grouped first by date and then by item
something like this

DateItemOrderQTYMfgQTY
1/2/2014Aa111222
1/2/2014Bb250300
1/2/2014Cc333------
2/2/2014Cc------333
3/3/2014Aa100------
3/2/2014Dd------250

Any idea?

Thanks for your help!

1 Solution

Accepted Solutions
swuehl
MVP
MVP

You can create a common fact table like this, then create a simple straight table with dimensions Date and Item and expressions sum(OrderQty) and sum(MfgQty):

Orders:

LOAD * INLINE [

    OrderID, OrderDate

    101, 1/2/2014

    102, 1/2/2014

    103, 3/3/2014

];

OrdersDetails:

Inner Join (Orders)

LOAD * INLINE [

    OrderID, ItemID, OrderQty

    101,    15,        111

    101,    16,        250   

    102,    17,        333

    103,    15,        100

];

MfgOrders:

LOAD * INLINE [

    MfgID, MfgOrderDate

    5101, 1/2/2014

    5102, 2/2/2014

    5103, 3/3/2014

];

Inner Join (MfgOrders)

MfgOrdersDetails:

LOAD * INLINE [

    MfgID, ItemID, MfgOrderQty

    5101,    15,        222

    5101,    16,        300   

    5102,    17,        333

    5103,    18,        250   

];

FACT:

LOAD *,OrderDate as Date Resident Orders;

CONCATENATE LOAD *, MfgOrderDate as Date Resident MfgOrders;

drop tables Orders, MfgOrders;

//Inner Join (Orders)

Items:

Load * INLINE [

    ItemID,    Item

    15,    Aaaa

    16,    Bbbb

    17, Cccc

    18,    Dddd   

];

View solution in original post

5 Replies
swuehl
MVP
MVP

You can create a common fact table like this, then create a simple straight table with dimensions Date and Item and expressions sum(OrderQty) and sum(MfgQty):

Orders:

LOAD * INLINE [

    OrderID, OrderDate

    101, 1/2/2014

    102, 1/2/2014

    103, 3/3/2014

];

OrdersDetails:

Inner Join (Orders)

LOAD * INLINE [

    OrderID, ItemID, OrderQty

    101,    15,        111

    101,    16,        250   

    102,    17,        333

    103,    15,        100

];

MfgOrders:

LOAD * INLINE [

    MfgID, MfgOrderDate

    5101, 1/2/2014

    5102, 2/2/2014

    5103, 3/3/2014

];

Inner Join (MfgOrders)

MfgOrdersDetails:

LOAD * INLINE [

    MfgID, ItemID, MfgOrderQty

    5101,    15,        222

    5101,    16,        300   

    5102,    17,        333

    5103,    18,        250   

];

FACT:

LOAD *,OrderDate as Date Resident Orders;

CONCATENATE LOAD *, MfgOrderDate as Date Resident MfgOrders;

drop tables Orders, MfgOrders;

//Inner Join (Orders)

Items:

Load * INLINE [

    ItemID,    Item

    15,    Aaaa

    16,    Bbbb

    17, Cccc

    18,    Dddd   

];

bilionut
Contributor III
Contributor III
Author

Hi swuehl,

Thank you very much for your help. It's work fine.

I have only one question: how could I do in this case decoding MONTH or YEAR from field Date?

Usually i do something like that at Load from table:

MONTH(Date) as Month,

YEAR(Date) as Year,

but now I'm a little confused about the correct syntax.

Thanks again!

anbu1984
Master III
Master III

You can use Month and Year function in this case also

FACT:

LOAD *,OrderDate as Date,Month(OrderDate) as OrderDateMonth,Year(OrderDate) as OrderDateYear Resident Orders;

CONCATENATE LOAD *, MfgOrderDate as Date Resident MfgOrders;

swuehl
MVP
MVP

You can look into the master calendar concept (search the forum for master calendar, there are tons of examples), linking the master calendar table to the Date field, or duplicating the calendar and link it to all date fields needed.

bilionut
Contributor III
Contributor III
Author

Hi swuehl,

I was able to creating a pivot according to your response solution.

Fact table looks like that

1.jpg

But how could I load a table with fields MfgOrderQty and OrderQty  on the same row, group by Date and ItemID