Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
kushalthakral
Creator III
Creator III

Count in script

Hi All

i have a file having data like

Model

Sales Date

a01/01/2013
a01/02/2013
a01/05/2013
b01/07/2013
b03/05/2013
b07/05/2013
b01/01/2013
c01/01/2013
c

01/03/2013

c03/03/2013
c01/02/2013
a05/05/2013

Now Actually i want to calculate the count of each model in a script and then find the ratio of each model with respect to total sales

in a script

Thanks

Kushal Thakral

1 Solution

Accepted Solutions
its_anandrjs

Load your table like below

Table:

LOAD * INLINE [

    Model,Sales Date

    a, 01/01/2013

    a, 01/02/2013

    a, 01/05/2013

    b, 01/07/2013

    b, 03/05/2013

    b, 07/05/2013

    b, 01/01/2013

    c, 01/01/2013

    c, 01/03/2013

    c, 03/03/2013

    c, 01/02/2013

    a, 05/05/2013];

Left Join

LOAD

Model,

Count([Sales Date]) as ModelCount

Resident Table

Group By Model;

Left join

LOAD 

Count([Sales Date]) as CntTotal 

Resident Table; 

Left Join

LOAD

Model,

Num((sum(ModelCount) / sum(CntTotal)),'#.#0%') as Ratio

Resident Table

Group By Model;

View solution in original post

10 Replies
SunilChauhan
Champion II
Champion II

Load Count(Model) as Modelcount,

[Source Date]

from path

group by [Source Date]

hope this helps

Sunil Chauhan
maxgro
MVP
MVP

where are sales?

kushalthakral
Creator III
Creator III
Author

Total sales means count of all dates together

Assume each as quantity 1 and add all models together as Sales

Not applicable

Hi,

Lets suppose your table name is "Sales". you can load another table from this table lets say ModelCount

NocConcatenate

ModelCount:

Load Count(Model) as ModelCount,

Model

Resident Sales

Group by Model;

then in your scrip you can write expression to get ratio like =Sum (Sales) / Sum (ModelCount)

MK_QSL
MVP
MVP

Use something like below

Count of Sales

COUNT(Model) or COUNT([Sales Date])

% Contribution

COUNT(Model)/Count(TOTAL Model)

maxgro
MVP
MVP

source:

load * inline [

Model, SalesDate

a, 01/01/2013

a, 01/02/2013

a, 01/05/2013

b, 01/07/2013

b, 03/05/2013

b, 07/05/2013

b, 01/01/2013

c, 01/01/2013

c, 01/03/2013

c, 03/03/2013

c, 01/02/2013

a, 05/05/2013

];

left join (source)

LOAD

Model, count(SalesDate) as cnt

Resident source

group by Model;

left join (source)

LOAD

count(SalesDate) as cnttotal

Resident source

;

table:

NoConcatenate load

Model, SalesDate,

1 / cnt as pct,

1 / cnttotal as pcttotal

Resident

source;

DROP Table source;

1.png

Gysbert_Wassenaar

See attached example.


talk is cheap, supply exceeds demand
SunilChauhan
Champion II
Champion II

in myscript use [Source Date] in count and model outside

load

count([Source Date]) as Totalcount,

Model

from path

group by Model;

Sunil Chauhan
its_anandrjs

Load your table like below

Table:

LOAD * INLINE [

    Model,Sales Date

    a, 01/01/2013

    a, 01/02/2013

    a, 01/05/2013

    b, 01/07/2013

    b, 03/05/2013

    b, 07/05/2013

    b, 01/01/2013

    c, 01/01/2013

    c, 01/03/2013

    c, 03/03/2013

    c, 01/02/2013

    a, 05/05/2013];

Left Join

LOAD

Model,

Count([Sales Date]) as ModelCount

Resident Table

Group By Model;

Left join

LOAD 

Count([Sales Date]) as CntTotal 

Resident Table; 

Left Join

LOAD

Model,

Num((sum(ModelCount) / sum(CntTotal)),'#.#0%') as Ratio

Resident Table

Group By Model;