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

Announcements
Posting on Qlik Community is temporarily paused. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Average sum group by months in load script

Good day!

In load script i load table from excel:

Main:

LOAD

  Id,

  Year(Date)&num(Month(Date),'00') as YearMonth,

  avg(Sum)

  FROM

$(DataPath)Test.xlsx

(ooxml, embedded labels, table is Sheet1)

;

in result i get table:

  

IdDateSum
101.01.20154
102.01.20156
103.01.20154
104.01.20156
105.01.201537
106.01.20154
107.01.20152
108.01.20157
109.01.20154
101.02.20154
102.02.20156
103.02.20153
104.02.20156
105.02.20153
106.02.20151
107.02.20153
108.02.20155
109.02.201576

How i load script calculate average sum group by YearMonth?

My necessary result:

Id     YearMonth     Sum

1     201501     8.2

1     201502    11.8

Thanks.

Labels (1)
1 Solution

Accepted Solutions
giakoum
Partner - Master II
Partner - Master II

Main:

LOAD

  Avg(Sum) as AvgSum,

  YearMonth

Group by

  YearMonth;

LOAD

  Id,

  Year(Date)&num(Month(Date),'00') as YearMonth,

  Sum

  FROM

Test.xlsx

(ooxml, embedded labels, table is Sheet1)

;

View solution in original post

11 Replies
giakoum
Partner - Master II
Partner - Master II

Main:

LOAD

  Avg(Sum) as AvgSum,

  YearMonth

Group by

  YearMonth;

LOAD

  Id,

  Year(Date)&num(Month(Date),'00') as YearMonth,

  Sum

  FROM

Test.xlsx

(ooxml, embedded labels, table is Sheet1)

;

Kushal_Chawda
MVP
MVP

Data:

Id,

  Year(Date)&num(Month(Date),'00') as YearMonth,

  Sum

  FROM

Test.xlsx

(ooxml, embedded labels, table is Sheet1);

Group:

noconcatenate

load Id,

YearMonth,

avg(Sum) as AvgSum

Resident Data

group by Id,YearMonth;


drop table Data;

Anonymous
Not applicable
Author

Thanks!!

How i can add filed id Id to result table?

awhitfield
Partner - Champion
Partner - Champion

Hi,

Just set the Dimension to YearMonth and the expression to Avg(Sum) and format the number as Integer 1dp

And you'll get:

Just add ID as another dim if required.

HTH Andy

Anonymous
Not applicable
Author

Thanks for advice.

But i need to do it in script level.

giakoum
Partner - Master II
Partner - Master II

depends

if you have multiple ids per year-month (and I guess you do) then you can't

How do you want it to look?

Anonymous
Not applicable
Author

Id     YearMonth     Sum

1     201501     8.2

1     201502    11.8

giakoum
Partner - Master II
Partner - Master II

is id always 1?

if yes, just add min(id) as id in the first load

giakoum
Partner - Master II
Partner - Master II

Main:

LOAD

  min(Id) as Id,

  Avg(Sum) as AvgSum,

  YearMonth

Group by

  YearMonth;

LOAD

  Id,

  Year(Date)&num(Month(Date),'00') as YearMonth,

  Sum

  FROM

Test.xlsx

(ooxml, embedded labels, table is Sheet1)

;