Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Join issue causing summing issues

We have an ancient Business App.   We have salespeople who get credit for split sales based on a percentage.  To calculate Invoice Sales, I sum the line items and then multiply the invoice total by each salesperson percent and our data balances fine.

A line of data might look like this

Order#SalespersonPercentInvoiceTotalSalespersonTotal
XYZ
Salesperson1
5010,0005,000
XYZSalesperson25010,0005,000

When we want to goto the item level detail we get a bad join

sum({ $< SalesType={'SLS'},  SalesCommissionFlag={'Y'},Date_InvoiceDate={">=$(=date(iDateBeg))<=$(=date(iDateEnd))"}>}  (Prod_SKU_SalesTotal *(Percent/100)))

Order#SalespersonPercentProductProduct TotalSalespersonTotal
XYZSalesperson150A4,0004,000
XYZSalesperson250A4,000

4,000

XYZSalesperson150B6,0006,000
XYZSalesperson250B6,0006,000

It seems like it is doing this because it is totaling the line item as 8,000 then applying the percent calculation.  If I add DISTINCT before the calculation it seems to work but causes problems elsewhere (like when I don't want detail and drop the salesperson dimension)

sum({ $< SalesType={'SLS'},  SalesCommissionFlag={'Y'},Date_InvoiceDate={">=$(=date(iDateBeg))<=$(=date(iDateEnd))"}>} DISTINCT (Prod_SKU_SalesTotal *(Percent/100)))

Order#SalespersonPercentProductProductLineItemTotalSalespersonTotal
XYZSalesperson150A4,0002,000
XYZSalesperson250A4,000

2,000

XYZSalesperson150B6,0003,000
XYZSalesperson250B6,0003,000

If I put in a Sum Table.   All totals fine.

If I put in Pivot Table, Sum totals are wrong

Very complicated, please see attached. 

4 Replies
Digvijay_Singh

If you don't want salesperson, you can hide the column instead of dropping. If this is the only problem after your own solution, then I think hiding columns should work. It is available in presentation tab of straight table.

Not applicable
Author

If you look in the pivot tables, the totals are wrong.  In reality, I put these into Pivot tables so I could total the problem with multiple orders.  I would rather put these in Sum Total tables which you cannot hide dimensions.  Simply hiding the salesperson is not the problem.

My totals only break on orders where we have multiple salespeople.  Iff the order only has 1 sales person, you get a proper 1:Many relationship between the OrderHeader and the Products.

When there is a split sale, we have a Many:Many relationship which I am not sure how to solve in this data model.

Originally the data comes in as

OrderSales1Percent1Sales2Percent2Sales3Percent3
xyz123Joe50Bob50

and I transform it to in my script

OrderSalespersonPercent
xyz123Joe50
xyz123Bob50

Not sure if this helps, but the problem lies in the data model or a better formula to calculate the line item and have it total proper and not the Table Dimensions.

Digvijay_Singh

Unfortunately I don't have licensed version so cannot see the qvw file attached. Hope other experts can help.

although I would be able to see data model by using binary load but cannot see the pivot table. I am downloading file to do the same but file is very big so taking time, having bad internet today. For attachment you have option to save it with reduced option to keep minimum file size.

Did you try expression using Aggr(Sum..you can play with different dimensions as long as it comply with the dimensions selected in the chart.

Not applicable
Author

Here is a reduced version