Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
vinod_nallapaneni

Stdev calculation for rolling 12 Months

Hi all,

          I'm facing an issue. I'm trying to find rolling 12 months standard deviation. I'm using expression as below but it won't work. PFA. sample data.

It would be appreciate if it is resolved.

Sqrt(pow(Sum({< MonthYear ={">=$(=Date(addmonths(Max(MonthYear), -11), 'MMM-YYYY')) <=$(=Date(addmonths(Max(MonthYear), 0),  'MMM-YYYY'))"}>} Quantity)-

Avg({<MonthYear ={">=$(=Date(addmonths(Max(MonthYear), -11), 'MMM-YYYY')) <=$(=Date(addmonths(Max(MonthYear), 0),  'MMM-YYYY'))"}>} Quantity),2)/

(Count({<MonthYear ={">=$(=Date(addmonths(Max(MonthYear), -11), 'MMM-YYYY')) <=$(=Date(addmonths(Max(MonthYear), 0),  'MMM-YYYY'))"}>}  Quantity))-1)


swuehl


Thanks in advance!

Vinod.

1 Solution

Accepted Solutions
MarcoWedel

Hi,

maybe one solution might be:

QlikCommunity_Thread_266433_Pic1.JPG

QlikCommunity_Thread_266433_Pic2.JPG

QlikCommunity_Thread_266433_Pic3.JPG

QlikCommunity_Thread_266433_Pic4.JPG

Stdev({$<MonthYear={"=MonthYear>AddMonths(Max(Total MonthYear),-6) and MonthYear<=Max(Total MonthYear)"}>} Quantity)

tabTemp:

CrossTable (MonthYearTxt, Quantity)

LOAD * FROM [https://community.qlik.com/servlet/JiveServlet/download/1300268-285808/Rolling%20Months%20STDEV.xlsx] (ooxml, embedded labels, table is Sheet1);

table1:

LOAD [Product Code],

     MonthName(Evaluate(MonthYearTxt)) as MonthYear,

     Quantity

Resident tabTemp

Where Evaluate(MonthYearTxt) and IsNum(Quantity);

DROP Table tabTemp;

hope this helps

regards

Marco

View solution in original post

8 Replies
effinty2112
Master
Master

Hi Vinod,

               You should take your table and load it into QV in columar form using crosstable:

Directory;

CrossTable(Month, Measure)

LOAD [Product Code],

     1*[42856] as [May 16],

     1*[42826] as [Jun 16],

     1*[42795] as [Jul 16],

     1*[42767] as [Aug 16],

     1*[42736] as [Sep 16],

     1*[42705] as [Oct 16],

     1*[42675] as [Nov 16],

     1*[42644] as [Dec 16],

     1*[42614] as [Jan 17],

     1*[42583] as [Feb 17],

     1*[42552] as [Mar 17],

     1*[42522]  as [Apr 17]

FROM

[Rolling Months STDEV.xlsx]

(ooxml, embedded labels, table is Sheet1);

The column headers were being read as numbers and the data was being read as dates so that's why the load statement might load a bit odd.

Then you can create this table:

Product Code Stdev (Measure)
184963.41
1693652511.6433
169366794.78802
1952538838.7917
19530428144.895
1953081759.5949
19532212091.516
237418422.27432
3650461477.3351
38219654542.093
413043355595.1
6003043264.2088
60030512690.232
60030914740.841
6004404401.0328
6004473439.0011
60711426327.474
60723418964.419
6072359917.0672
6072405930.7094
6072418302.817
6072485935.7247
6072562495.307
60725712208.315
60725914985.034
60726071998.184
6072622670.8554
60726311184.666
607279449.27924
6072966142.8894
60729910734.967
6073004669.2042
6073054078.696
6073147224.505
6073159759.8299
6073596742.7094
608344307.59145
6084991496.8174
608501236.60163
608502479.15202
6085032124.6348
6086277973.3361
60942613359.804
60942713079.209
60942835046.933
60943142447.42
60943410372.408
6094723803.5816
6094734977.0702
6094811121.2113
609574568.51385
6095789615.9451
60960914749.54
6096612369.3326
6113871985.5187
6113883389.3431

cheers

Andrew

vinod_nallapaneni
Author

Hi Andrew,

               Thanks for your response.

Firstly I'm having same format in QV. I think that doesn't require cross table. Is there any possibility to do it in front-end?

Please let me know if it is possible.

-Vinod.

Anil_Babu_Samineni

stalwar1mrkachhiaimpmarcowedel

please help him, Free to ask if required to work related. His intention mainly is Standard Deviation and then Rolling month for that standard deviation.

I even don't know how to write set analysis for Standard deviation. Can you try this for me?

If(Only({< MonthYear ={">=$(=Date(addmonths(Max(MonthYear), -11), 'MMM-YYYY')) <=$(=Date(addmonths(Max(MonthYear), 0),  'MMM-YYYY'))"}>} MonthYear), Stdev(Aggr(Avg(Quantity), MonthYear))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
MarcoWedel

Hi,

maybe one solution might be:

QlikCommunity_Thread_266433_Pic1.JPG

QlikCommunity_Thread_266433_Pic2.JPG

QlikCommunity_Thread_266433_Pic3.JPG

QlikCommunity_Thread_266433_Pic4.JPG

Stdev({$<MonthYear={"=MonthYear>AddMonths(Max(Total MonthYear),-6) and MonthYear<=Max(Total MonthYear)"}>} Quantity)

tabTemp:

CrossTable (MonthYearTxt, Quantity)

LOAD * FROM [https://community.qlik.com/servlet/JiveServlet/download/1300268-285808/Rolling%20Months%20STDEV.xlsx] (ooxml, embedded labels, table is Sheet1);

table1:

LOAD [Product Code],

     MonthName(Evaluate(MonthYearTxt)) as MonthYear,

     Quantity

Resident tabTemp

Where Evaluate(MonthYearTxt) and IsNum(Quantity);

DROP Table tabTemp;

hope this helps

regards

Marco

vinod_nallapaneni
Author

Hi Anil,

          Thanks for your support.

I've tried your expression but it was not working. As I understood it was calculating first avg and then stdev. So, it is failed to calculate stdev for 1 value.

-Vinod.

vinod_nallapaneni
Author

Hi Marco,

            You are right. But I want to calculate not only stdev but also other formulas. While I'm using cross table it is working but it was effecting on other formulas. Is there any other solution apart from cross table? I want to calculate rolling months Stdev in front-end. Please let me know if you have any other idea.

-Vinod.

MarcoWedel

You might load with and without crosstable in the same application to implement this solution while keeping your existing ones.

Regards

Marco

MarcoWedel

Hi,

I guess without crosstable loading your sample table (except for generic field renaming) you would have to deal with monthly changing field names that do not contribute to a combined MonthYear field.

If for whatever reason you cannot change the data model accordingly, one front end solution might be:

(not meant as a recommended solution but as proof that (like in most cases) it could be done in QlikView)

QlikCommunity_Thread_266433_Pic5.JPG

QlikCommunity_Thread_266433_Pic6.JPG

RangeStdev([May 2017],[Apr 2017],[Mar 2017],[Feb 2017],[Jan 2017],[Dec 2016])

or without using static field names:

QlikCommunity_Thread_266433_Pic7.JPG

RangeStdev($(=Concat('['&MonthName(AddMonths(Today(),-ValueLoop(2,7)))&']',',')))

(to be changed to ValueLoop(0,5) if, unlike in this example, data is available up to the current month)

tabTemp:

CrossTable (ColNam, ColHdr)

LOAD 1,* FROM [https://community.qlik.com/servlet/JiveServlet/download/1300268-285808/Rolling%20Months%20STDEV.xlsx] (ooxml, no labels, table is Sheet1)

Where RecNo()=1;

mapFieldNames:

Mapping

LOAD ColNam,

    If(Evaluate(ColHdr),MonthName(Evaluate(ColHdr)),ColHdr)

Resident tabTemp;

DROP Table tabTemp;

table1:

LOAD * FROM [https://community.qlik.com/servlet/JiveServlet/download/1300268-285808/Rolling%20Months%20STDEV.xlsx] (ooxml, no labels, header is 1 lines, table is Sheet1);

RENAME Fields using mapFieldNames;

hope this helps

regards

Marco