Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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!

1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

You are using the wrong ItemName field, you should be using Returned.ItemID

I've added ItemName to the returned table, you can choose to join or Keep them in a separate table.

I've just commented the Join statement in the script

sample2.JPG

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

View solution in original post

40 Replies
vinieme12
Champion III
Champion III

Can you post sample excel ?

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

Hi Vineeth,

I added Excel file.

Thank You!

vinieme12
Champion III
Champion III

Can you explain the relationships please?

Items 1  -  M Delivery

Item 1  - 1 Offer ?   or Item 1 - M Offers ?

What is the relationship between Delivery and Offer?

do you really need DeliveryId in DeliveryOffer table??

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

Will check and get back in sometime

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

Hi,

I attached the flattened hierarchy file of the dimensions as QVD.

I created a similar scenario to the one in reality.

Delivery can have one or more offers.

The same item can be linked to different offers. That's why I created the key: Key_Delivery_Offer_Item.

In the fact table with the customer deliveries I have only DeliveryID.

I don't want to create the items for all deliveries because in the real project it will end up

with tens of millions of records.

Is it clearer now?

Thanks!

vinieme12
Champion III
Champion III

Check the attached, you can use the Returned flag to see if that delivery was returned.

272535.JPG

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

Hi Veneeth,

Thanks for helping!

It's not clear to me how i get the metrics for the delivered items in your solution.

For example, customer 111 delivered items not returned are:

Customer_111_deliveries.png

In your solution, it's not clear how i can see them:

Customer_111_Returns.png

Thanks for your patience 🙂

dafnis14
Specialist
Specialist
Author

In my model, I added a field:

1 as Qty_Delivered

in the Qty Delivered metric I wrote:

Sum(aggr(sum( Qty_Delivered),Delivery_Name,Offer_Name, Item_Name))

vinieme12
Champion III
Champion III

to count the deliveries that are not returned you should be using the flag that has been created

Example

Deliveries that were not returned will be

Count({<ReturnedFlag-={1}>}Distinct DeliveryID)   /// not equal to 1



Deliveries that were returned will be

Count({<ReturnedFlag={1}>}Distinct DeliveryID)     // equal to 1

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