Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
shane_spencer
Specialist
Specialist

Advice of Table Structure

I've been given an App that I need to do some more development and I'm wanting some advice on how to structure the table(s) to get the data in a format that best suits my purposes. Presently there are two tables - Goods Dispatched and Invoices for these.

synthetic.PNG

As you can see there's a synthetic key which I'm not happy about BUT it does the job. i.e the Company / Country / Year / Month are from BOTH tables, the VAT is from INVOICES and the Intrastat is from GOODS. By selecting from the list boxes the data in the table will show the comparison for specific Months, Company, Country etc. There's even another chart that will show a more detailed breakdown by Invoice number.

comparison.png

If I break the synthetic join the table does not work - even if I use set analysis to equate Goods Month to Invoice Month etc. (Though set analysis works well if I create separate charts with the dimensions specific to the expression).

I was thinking of creating one Table of data instead. But what would be best? just create the missing fields - these are more dimensions such as customer name and tax rate etc - in each data set so they concatenate? or join the Tables using the LINK field (which is essentially an Invoice number that exists in both)? The tricky bit is that the Month/Year in GOODS may be different to the Month/Year in INVOICES for each order as they are not dispatched and billed at exactly the same time so I'm unsure how that would affect the decision. 

Really after some advice please.

1 Solution

Accepted Solutions
Kushal_Chawda

That all depends on the granularity on which your fact exists. If your invoices are exists till month level and Goods just at Year level then you can create iLINK  & gLINK as both the Fact are available at different level, but if your Invoice and Goods Fact are at same level then no need to create the separate link you can go with 3 way link approach

View solution in original post

14 Replies
prieper
Master II
Master II

What is the content of your fields, i.e. does YEAR have the exact meaning in both tables (GOODS and INVOICES)?

If not, it may be wise to rename these fields into YEAR_Goods and YEAR_Invoices etc.

Else please post an example

its_anandrjs

Better you can go for the Concatenate as you see that there are many fields are common but some metric are differs

InvoiceAndGoods:

Load * ,'Invoice' as TabFlag From Invoice;

Concatenate(InvoiceAndGoods)

Load * ,'Goods' as TabFlag From Goods;

It is best approach and when doing reporting use the TabFlag selection for getting values from that table it is easy for you.

shane_spencer
Specialist
Specialist
Author

I've got to be careful what data I post unfortunately. However the Month/Year in GOODS will be date it was dispatched and the Month/Year in INVOICES will be the date it was billed - so it's not exactly the same. But then if I rename them the Chart does not work because there's no synthetic join.

shane_spencer
Specialist
Specialist
Author

Would you concatenate the Month/Year fields?

its_anandrjs

Make a Key in both tables then and link it with this key and on this separated tables create different Year and Month fields for Invoice and Goods.

Invoice:

Load

Year&'_'&Month&'_'&Period&'_'&Company&'_'&Country&'_'&Link as Key

Year as Invoice_Year,

Month as Invoice_Month,*

From Invoice;

Goods:

Load

Year&'_'&Month&'_'&Period&'_'&Company&'_'&Country&'_'&Link as Key

Year as Goods_Year,

Month as Invoice_Month,*

From Goods;



Kushal_Chawda

I would advice to create the link table for both the tables

Invoices:

LOAD *,

            autonumber(Year&'|'&Month&'|'&Period &'|'&Company&'|'& Country &'|'&Link) as Key

FROM Invoices;

Goods:

LOAD *,

          autonumber(Year&'|'&Month&'|'&Period &'|'&Company&'|'& Country &'|'&Link) as Key

FROM Invoices;

LinkTable:

LOAD distinct

Key,

Key as Key1,

Year,

Month,

Period ,

Company,

Country,

Link

resident Invoices;


concatenate(LinkTable)

LOAD distinct

Key,

Year,

Month,

Period ,

Company,

Country,

Link

resident Goods

where not exists (Key1,Key);


drop field Key1;


Note:

Please comment Year,Month,Period ,Company,Country,Link fields from both table (Invoices & Goods). I have used LOAD * as I don't know what other fields are there in your table. So it simple means that, keep only measures in Invoices & Goods table as dimensions are added in the link table




prieper
Master II
Master II

Hi Spane,

you need to be careful: fields, who are different, should not be matched.
Within QV you should then choose a different name, else you would link dates with dispatch with billing.

Looks as if there is a 1:n-relation in your model, concatenation is not a good idea.

What is the meaning of the "LINK"-field in your datamodel?

shane_spencer
Specialist
Specialist
Author

Having the Year/Month as part of the Key - will that cause problems when I try to do a Reconciliation and the Invoice and Goods months are different?

shane_spencer
Specialist
Specialist
Author

It's a Combination of COMPANY and INVOICE NUMBER. Not sure why these have been combined by the creator but the Invoice Number is the common field between the two sets of data. i.e. For every GOOD dispatched there will be an invoice number, and that same invoice number will be in INVOICES data but perhaps for a different Month/Year.

The idea of the Tool is to compare the Values (currency) of what's been dispatched and what's been billed and the two should balance. The users want to look at this data by narrowing down to certain months, companies, countries etc. but at the same time the Month of billing and dispatch may differ so the comparison may not match. So I've got to look at creating a higher level chart that matches the two sets of values irrespective of month.