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

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

<<CORRECTION>>

Example

Deliveries that were not returned will be

count({<%KEY_ReturnedDelivery={"=isnull(Returned.ReturnedFlag)"}>}DISTINCT DeliveryID)


Deliveries that were returned will be

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

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

Unfortunately , it doesn't work...

Count({<Returned.ReturnedFlag-={1}>}Distinct DeliveryID)

The returned quantity is also wrong...

Metrics_with_flag.png

vinieme12
Champion III
Champion III

just made a correction above

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

Not there yet... 😞

Customer_222.png

vinieme12
Champion III
Champion III

The returned quantity is also wrong...

How is it wrong when we are counting Distinct DeliveryID?

and you can see Customer 111 has returned only DeliveryID  =1 , so that is correct


if you want to see how many offers then change to Distinct  Returned.OfferID  or

distinct   Returned.ItemId to see how many Items were returned

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

Sorry; but you have to tell me clearly what you values you expect to see!

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

The returned quantity is also wrong...

How is it wrong when we are counting Distinct DeliveryID?

and you can see Customer 111 has returned only DeliveryID  =1 , so that is correct


if you want to see how many offers then change to Distinct  Returned.OfferID  or

distinct   Returned.ItemId to see how many Items were returned

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

for customer 111 it shows:

Cust_111_New.png

I attached the desired output in the post:

When a customer is selected, it should display the relevant quantities.

This is where I was stuck.. because I Had trouble to add a customer key..

Metrics_Delivered_Returned.png

Thanks!

dafnis14
Specialist
Specialist
Author

Hi,

I think the issue is because there isn't a record for Delivery ID that has return items, like the ones created for 2 and 3.

That's why I can't count delivered items for delivery 1.

Cust_111_missing_delivery.png

vinieme12
Champion III
Champion III

I don't know what you are trying to achieve now, can you tell me exact numbers that you expect to see!!

as i already gave you the expressions to use

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

<<CORRECTION>>

Example

Deliveries that were not returned will be

count({<%KEY_ReturnedDelivery={"=isnull(Returned.ReturnedFlag)"}>}DISTINCT DeliveryID)


Deliveries that were returned will be

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



Can you post what expressions you are using?

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