Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
EdgarMM
Contributor III
Contributor III

SUM IF Comparation with Set Analysis

Hi there

       I hope that you can help me; I have a table with the budget and sales information and I want to create a pivot table that has to show only the products with an Over Sales, that is, products that exceeded the budget but only the amount of the difference between the Sales and the budget, for example, if the budget of a product is 100 USD and the sales were 120 USD, I want the table to only show 20 USD which is the excess of sales. My expresion so far is:

Where:

Sales_Order_Year = Is the dinamic Year Selected

Budget = It is an indicator for those products that do have a sales budget

Source = Source or data, for Sales the ERP System for Budget it is a variable $(Versus) that it is a version selected of the budget

 

IF((
//SALES
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source = {'ERP'}>} Domestic_Amount_USD))
/
// BUDGET
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source={'$(=$(Versus))'}>} Bgt_Amount_USD))
) >1,
(
//SALES
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source = {'ERP'}>} Domestic_Amount_USD))
-
// BUDGET
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source={'$(=$(Versus))'}>} Bgt_Amount_USD))
)
, 0)

 

My Table

PRODUCTBgtSalesThis is the correct ammount  This is what I´m getting on the pivot table
Total   23,587.91   24,008.78   4,605.66                                                         420.87
A5770.206787.641017.431017.43
B666.471629.67963.20963.20
C447.031350.32903.29903.29
D814.091196.14382.05382.05
E404.16727.70323.54323.54
F223.20533.62310.42310.42
G229.06400.83171.77171.77
H420.75559.62138.87138.87
I81.00200.77119.78119.78
J248.40322.5774.1674.16
K93.97150.0956.1256.12
L110.47155.1644.6844.68
M160.94189.3028.3628.36
N88.65108.9520.2920.29
O124.93144.7319.7919.79
P101.89110.018.128.12
Q44.6552.758.108.10
R39.2947.227.937.93
S131.07138.827.757.75
T188.12186.820.00-1.30
U20.5513.010.00-7.54
V12.004.200.00-7.80
W12.020.000.00-12.02
X14.250.000.00-14.25
Y71.0053.290.00-17.71
Z150.48125.850.00-24.63
AA41.0412.320.00-28.72
AB2829.032760.870.00-68.16
AC128.7340.280.00-88.45
AD384.52282.320.00-102.19
AE117.738.570.00-109.16
AF318.08205.620.00-112.46
AG1061.31900.350.00-160.97
AH183.540.000.00-183.54
AI1886.671693.690.00-192.98
AJ439.92193.420.00-246.50
AK627.00108.450.00-518.55
AL804.6012.870.00-791.73
AM4097.102600.960.00-1496.13

 

The table I want to obtain is:

PRODUCTOver Sales
Total       4,605.66
A1017.43
B963.20
C903.29
D382.05
E323.54
F310.42
G171.77
H138.87
I119.78
J74.16
K56.12
L44.68
M28.36
N20.29
O19.79
P8.12
Q8.10
R7.93
S7.75

 

Thanks in advanced for your help.

 

Regards,

Edgar.

 

1 Solution

Accepted Solutions
EdgarMM
Contributor III
Contributor III
Author

Hi there

 

     I found a way to solve this using the aggr function before the expression :

 

=(sum(aggr(IF((
//SALES
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source = {'ERP'}>} Domestic_Amount_USD))
/
// BUDGET
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source={'$(=$(Versus))'}>} Bgt_Amount_USD))
) >1,
(
//SALES
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source = {'ERP'}>} Domestic_Amount_USD))
-
// BUDGET
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source={'$(=$(Versus))'}>} Bgt_Amount_USD))
)
, 0), Product).

 

Regards,

Edgar.

View solution in original post

3 Replies
tresesco
MVP
MVP

So it's kind of avoiding neg values from Sales-Budget. Try like:

=RangeMax( SalesExp - BudgetExp, 0)

EdgarMM
Contributor III
Contributor III
Author

Thanks for your kind response, I tried using RangeMax as suggested but I'm getting the same result, the pivot table resultant is not showing the negative results anymore, but in the total of the column, it looks like the negatives are been considered. My table result after using RangeMax:

PRODUCTRangeMax
Total           420.87
A1017.43
B963.20
C903.29
D382.05
E323.54
F310.42
G171.77
H138.87
I119.78
J74.16
K56.12
L44.68
M28.36
N20.29
O19.79
P8.12
Q8.10
R7.93
S7.75

 

Regards,

Edgar.

 

EdgarMM
Contributor III
Contributor III
Author

Hi there

 

     I found a way to solve this using the aggr function before the expression :

 

=(sum(aggr(IF((
//SALES
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source = {'ERP'}>} Domestic_Amount_USD))
/
// BUDGET
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source={'$(=$(Versus))'}>} Bgt_Amount_USD))
) >1,
(
//SALES
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source = {'ERP'}>} Domestic_Amount_USD))
-
// BUDGET
(sum({$<Sales_Order_Year = {$(#=Only(Sales_Order_Year))}, [Budget]={'Yes'}, Source={'$(=$(Versus))'}>} Bgt_Amount_USD))
)
, 0), Product).

 

Regards,

Edgar.