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: 
dafnis14
Specialist
Specialist

How to link 2 Fact tables that share Hierarchy and a key

Hi,

After exploring numerous blogs and discussions (like the one below)

https://community.qlik.com/message/547634#547634

I still couldn't figure out a solution for my issue..

I have a balanced  Hierarchy:

Delivery > Offer >Item

Hierarchy.png

One fact table (Deliveries) is link to the highest level (DeliveryID) and one (Customer Returns) to the lowest (Key_Delivery_Offer_Item).

Facts_Link_to_Dimensions.png

For both I need to sum by the item level which is working fine:

Metrics_Delivered_Returned.png

But when I add the customer key, I get a circular reference:

Circular_in_hierarchy.png

I think Generic Key or concatenation is not a solution because I need all the hiearchy levels for both fact tables.

Any idea how to handle this?

Thanks!

40 Replies
vinieme12
Champion III
Champion III

Check the attached

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
dafnis14
Specialist
Specialist
Author

Unfortunately something is wrong.

You still miss delivery that has  return items in them delivery 1 for customer 111..)

Your solution:

Vineeth_111.png

Mine Only with deliveries:

My_111.png

Is a link table between the 2 fact tables possible?

Thanks again for your efforts!

vinieme12
Champion III
Champion III

You still miss delivery that has  return items in them delivery 1 for customer 111..)

Which one?


You absolutely cannot have ItemName in the Deliveries table; because you don't have that data!


You only have ItemName for the returned deliveries

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
vinieme12
Champion III
Champion III

I don't know how you are evaluating it even after me giving you the expressions to use!!

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
dafnis14
Specialist
Specialist
Author

I am definitely aware that I miss the item ID for the deliveries. But I got it counted right without the customers.

I'm referring to your model: you can see that it does not show all items that were delivered.

For customer 111 - delivery ID 1 is not included in the "not returned" Table.

Vineeth_111.png

In order to be able to see these missing deliveryIDs

I thought maybe to add the following your script:

Tmp:

LOAD Distinct %KEY_ReturnedDelivery as Tmp_%KEY_ReturnedDelivery

Resident TransactionTable

Where Returned.ReturnedFlag =1;

Concatenate (TransactionTable)

LOAD * Where  Exists(Tmp_%KEY_ReturnedDelivery, %KEY_ReturnedDelivery)

;

LOAD CustomerID,

     DeliveryID,

     DeliveryID as DeliveryIDtoOffer,

     CustomerID&'_'&DeliveryID as %KEY_ReturnedDelivery,

     1 as Flag_AddDeliv

 

FROM

Items Deliveries.xlsx

(ooxml, embedded labels, table is [Customer Deliveries]);

vinieme12
Champion III
Champion III

For customer 111 - delivery ID 1 is not included in the "not returned" Table.

Just Check back with your Data to verify

Customer 111 has Delivery id's 1,2 and 3

CustomerIDDeliveryIDCity
1111NY
1112NY
1113NY

and in the Returned Delivery Customer 111 has Delivery id 1,

so if Delivery ID 1 has been returned why would it appear in then"NOT RETURNED" table??

    

CustomerIDDeliveryIDOfferIDItemID
111112
111113
Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
vinieme12
Champion III
Champion III

if you just want a count of Deliveries irrespective of returnedflag just remove the set analysis

Dimension

      CustomerID

Expression

     Count(distinct DeliveryID)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
dafnis14
Specialist
Specialist
Author

Ahh, ok...

We have to know what was delivered - by the item id, per customer

and what was returned - by the by the item id, per customer....

This is in order to be able to analyze it.


In reality, we are talking about sent and redeemed coupons 🙂


Thanks!

dafnis14
Specialist
Specialist
Author

Hi,

I added to your model a summary table.

The delivered items look fine!

But the returned items are not counted as expected.

Could you please help me figure out why?

Thanks!

Returned.png

vinieme12
Champion III
Champion III

what expression have you used?

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.