Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Counting issues in table object

Hi all,

I have problem counting when including a field from a dimension table. I have an order number with some lines in my fact table. The order total qty is 200, and the correct total sales amount is 136 240,-. Below is my table object. As you can see, there's a duplicate on order line 50000. That's because this line is connected to two different shipments. If I remove the ShipmentNo field the calculations will be correct.

This is my data model and code (simplified):

Fact:

Load * Inline [

    RecNo, OrderNo, OrderLineNo, Shipment_Key, Qty, SalesAmount

    1, KO01542142, 10000, 1, 40, 0

    2, KO01542142, 30000, 2, 40, 6600

    3, KO01542142, 40000, 3, 40, 4000

    4, KO01542142, 50000, 4, 40, 6000

    5, KO01542142, 80000, 5, 10, 29910

    6, KO01542142, 80000, 5, 10, 29910

    7, KO01542142, 80000, 5, 10, 29910

    8, KO01542142, 80000, 5, 10, 29910

];

Shipment:

Load * Inline [

    Shipment_Key, ShipmentNo

    1, -

    2, LO01665695

    3, LO01665633

    4, LO01590308

    4, LO01672135

    5, LO01686726

];

Can I somehow make a calculation in my table object that solves this problem..? Don't wanna change my data model.

3 000,- at each row is good enough. I have tried Sum(SalesAmount) / Count(OrderLineNo) but that will not be correct for line 8000, which has multiple rows in my fact table...

This must be a quite common problem I guess...

Please answer with your suggestions

Best regards

Filip

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Rather than using ShipmentNo as a dimension, use Concat(ShipmentNo, ', ') as an expression,

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

5 Replies
awhitfield
Partner - Champion
Partner - Champion

Hi Filip,

is it correct that you have 2 different shipment numbers for shipment key 4 ?

Andy

MayilVahanan

Hi

Try like this

OrderNo OrderLineNo ShipmentNo =SUm(Qty) =If(RowNo() = 0 or IsNull(RowNo()), Sum(SalesAmount), Sum(SalesAmount) / Count(TOTAL<OrderNo, OrderLineNo> ShipmentNo))
200 136240
KO0154214210000-400
KO0154214230000LO01665695406600
KO0154214240000LO01665633404000
KO0154214250000LO01590308403000
KO0154214250000LO01672135403000
KO0154214280000LO0168672640119640
Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
jonathandienst
Partner - Champion III
Partner - Champion III

Rather than using ShipmentNo as a dimension, use Concat(ShipmentNo, ', ') as an expression,

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
swuehl
MVP
MVP

If you use a straight table chart with total mode expression total, I can't reproduce your results:

OrderNo OrderLineNo ShipmentNo Sum(Qty) Sum(SalesAmount)
200 136240
KO0154214210000-400
KO0154214230000LO01665695406600
KO0154214240000LO01665633404000
KO0154214250000LO01590308406000
KO0154214250000LO01672135406000
KO0154214280000LO0168672640119640
Anonymous
Not applicable
Author

Thank you for this solution, it fits me best. Didn't think in this way..

Best,
Filip