Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
upaliwije
Creator II
Creator II

Sales Ratio

Hi Friends

I have following sales data in a worksheet

DeptPrdAmount
1A2000
1B1000
1C3000
1D4000
2A2500
2B1500
2D5000
2E6000
3E3500
3D8500
3C1000
3B5000

When I load data I want to modify the script to have another column in the table showing the % of sales of each Prd in each dept

In other words my table view should show data in following format. Pls help me to modify the script to obtain what I want . I have attached my QVW pls

 

DeptPrdAmountRatio
1A200020%
1B100010%
1C300030%
1D400040%
2A250017%
2B150010%
2D500033%
2E600040%
3E350019%
3D850047%
3C10006%
3B500028%
1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

If you want to do this at back end use this..

Data:

LOAD * Inline

[

  Dept,Prd,sales,

  1, A, 2000

  1, B, 1000

  1, C, 3000

  1, D, 4000

  2, A, 2500

  2, B,  1500

  2, D, 5000

  2, E, 6000

  3, E, 3500

  3, D, 8500

  3, C, 1000

  3, B, 5000

];

Left Join (Data)

Load Dept, SUM(sales) as TotalSales Resident Data Group By Dept;

Left Join (Data)

Load Dept, Prd, Num(sales/TotalSales,'#0%') as ratio Resident Data;

If you don't want to change script and want to do it at front end.. use this

create a straight or pivot table


Dimension

Dept

Prd

Expression

SUM(sales)

SUM(sales)/SUM(Total <Dept>sales)

View solution in original post

10 Replies
MK_QSL
MVP
MVP

If you want to do this at back end use this..

Data:

LOAD * Inline

[

  Dept,Prd,sales,

  1, A, 2000

  1, B, 1000

  1, C, 3000

  1, D, 4000

  2, A, 2500

  2, B,  1500

  2, D, 5000

  2, E, 6000

  3, E, 3500

  3, D, 8500

  3, C, 1000

  3, B, 5000

];

Left Join (Data)

Load Dept, SUM(sales) as TotalSales Resident Data Group By Dept;

Left Join (Data)

Load Dept, Prd, Num(sales/TotalSales,'#0%') as ratio Resident Data;

If you don't want to change script and want to do it at front end.. use this

create a straight or pivot table


Dimension

Dept

Prd

Expression

SUM(sales)

SUM(sales)/SUM(Total <Dept>sales)

tresesco
MVP
MVP

PFA

MK_QSL
MVP
MVP

In case, if you have same product more than once in same dept.. use as below..

Data:

LOAD * Inline

[

  Dept,Prd,sales,

  1, A, 500

  1, A, 1500

  1, B, 1000

  1, C, 3000

  1, D, 4000

  2, A, 2500

  2, B,  1000

  2, B,  500

  2, D, 5000

  2, E, 6000

  3, E, 2000

  3, E, 1500

  3, D, 8500

  3, C, 1000

  3, B, 5000

];

Left Join (Data)

Load Dept, SUM(sales) as TotalDeptSales Resident Data Group By Dept;

Left Join (Data)

Load Dept, Prd, SUM(sales) as TotalDeptPrdSales Resident Data Group By Dept, Prd;

Left Join (Data)

Load Dept, Prd, sales, Num(TotalDeptPrdSales/TotalDeptSales,'#0%') as Ratio Resident Data;

upaliwije
Creator II
Creator II
Author

Thanks a lot to both of for your prompt reply. Both answers are correct

upaliwije
Creator II
Creator II
Author

In a further Development I want to apportion the following expenses among the Prds and the output table should be like given below

DeptExpenseamountPrdRatio Exp_amount
1salary2000A20% 400
1salary2000B10% 200
1salary2000C30% 600
1salary2000D40% 800
1rent5000A20% 1,000
1rent5000B10% 500
1rent5000C30% 1,500
1rent5000D40% 2,000
2salary4000A17% 667
2salary4000B10% 400
2salary4000D33% 1,333
2salary4000E40% 1,600

Pls Help

tresesco
MVP
MVP

May be :

Sum(Ratios)*Sum(sales)/100

upaliwije
Creator II
Creator II
Author

Could you please explain me how to load expenses into data model

tresesco
MVP
MVP

What is the logic of defining expense type?

upaliwije
Creator II
Creator II
Author

name of Expense Like Salary, Rent, Travelling. They are in a separate table

DeptExpenseamount
1salary2000
1rent5000
2salary4000
3salary1000
3rent2500
3travelling3500