Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Help needed on cumulative range sum in Straight table

Hi All,

I need some advice on complex Range sum or set analysis expression which can accumulate Column 1 previous 12 records net value to be displayed in column2.

Here i am attaching example.

In the below excel is exported straight table from qlikview

Sum of 4A(Net Elgbl $) 12 months value is 643,910.565.26 but my expression returns incorrect value.

Can some one advice whats the wrong with formula or advice me if it is aggregating incorrectly.

4A(12M Elgbl $) Expression is

Sample qvw attached.

Appreciate your help

1 Solution

Accepted Solutions
swuehl
MVP
MVP

See my previous post, applying only() with set expression around Ratio.

View solution in original post

16 Replies
sunny_talwar

Have you made any selections when you exported out the table? I am seeing different numbers for the column 4A(12M Elgbl $), but the same numbers for 4A(Net Elgbl $)

Finding it hard to understand what exactly needs to be checked and resolved.

Best,

Sunny

swuehl
MVP
MVP

I believe this issue is caused by the fact that your field AsOfPeriod shows a load order that is not chronologic (create a list box with sort order Load order for field AsOfPeriod).

The method using rangesum with an advanced aggregation needs a properly sorted field as aggr() dimension,because aggr() always uses load order for its dimension values.

Looking at your script, I think the issue arise from use of distinct on your master calendar, which unfortunately reorders the master calendar values.

Try a master calendar without DISTINCT:

T:

LOAD

// Year(Temp_Date) * 100 + Month(Temp_Date) as [Period],

    Date(MakeDate(Year(Temp_Date),Month(Temp_Date)),'YYYYMM') as Period1,

  AutoNumber(Year(Temp_Date) * 100 + Month(Temp_Date)) as [Period_Ref],

  Year(Temp_Date)   as [Year],

  Month(Temp_Date) as [Month],

  Date(Temp_Date, 'YYYY-MM')   as [Year-Month],

  Year(Temp_Date)&'Q' & Ceil(Month(Temp_Date) / 3) as [YYYY-QQ],

  'Q' & Ceil(Month(Temp_Date) / 3)   as [Quarter]

  ;

LOAD

  MonthStart($(vMinDate), IterNo() - 1)   as Temp_Date

AUTOGENERATE (1)

WHILE monthstart($(vMinDate), IterNo() - 1) <= $(vMaxDate);

Anonymous
Not applicable
Author

Thanks swuehl and Sunny,

Removed Distinct from MasterCalendar load but still it did not work;

swuehl
MVP
MVP

The load order is still not correct, have a look at the list box ordered by load order.

swuehl
MVP
MVP

You are using a binary load. Does this load contain already an AsOfPeriod field?

Anonymous
Not applicable
Author

Hi Swuehl,

Thanks your help, Now i am halfway through.. I am able to get rolling 12 months numbers If i don't apply filter or if i select year 2020 still i need to able to see same number 4A(12M Elgbl $) : 643,910,800.77 instead of 39,337,623.26.

Appreciate if your help if we can fix this with set analysis but i did not succeeded.

Attached updated qvw.

swuehl
MVP
MVP

sum( aggr( rangesum( above(

Sum({<PeriodType = {'Current'}, AsOfPeriod= ,Year =  >} ProductSales)

-

Round(Num( ((Sum({<PeriodType = {'Rolling12'}, AsOfPeriod= ,Year = >}[In EGBL Units]) + (Sum({<PeriodType = {'Rolling12'}, AsOfPeriod= ,Year =  >}[In EGBL Units]) * only({<AsOfPeriod=, Year=>} Ratio) )) / Sum({<PeriodType = {'Rolling12'} , AsOfPeriod= ,Year = >} ProductGrams)),'#.00000')

*

Sum({<PeriodType = {'Current'}, AsOfPeriod= ,Year = >} ProductGrams)

)

*

(Sum({<PeriodType = {'Current'}, AsOfPeriod= ,Year =  >} ProductSales) / Sum({<PeriodType = {'Current'} , AsOfPeriod= ,Year = >} ProductGrams))

,0,12) ),NDC11,AsOfPeriod))

Anonymous
Not applicable
Author

only({<AsOfPeriod=, Year=>} Ratio) Ratio is at NDC11 level and hence I don't need above statement.

I have my Range sum expression like this


sum( aggr( rangesum( above(

     Expression to calculate current month Net sales

,0,12) ),NDC11,AsOfPeriod))      ===> Aggregating 12 months net sales.


Here problem i am facing is when i select Year 2020 then 2010 Jan Current Month Net Sales and 12 Months Net sales same.


I need set analysis to calculate 12 months aggregated net sales even though i selected sp0ecific year.


swuehl
MVP
MVP

This is the table I get when selecting Year 2020.

NDC11AsOfPeriod1A Sales1A UnitsWAC12M DS12M Units3C=3A+3B3E3G (In Elgbl $)3G (In Elgbl Units)4A(Net Elgbl $)4A(12M Elgbl $)4A(Net Elgbl Units)4A(12M Elgbl Units)6C=6A-6B6E7C=7A-7B7E8C=8A-8B8ECM ConcessionsFinal AMP $Final AMP Price $3F12WAC3G 12M (In Elgbl $)Column(4) - [3G 12M (In Elgbl $)]
5024200600120200156852725.275615293052194.00933107434.84486342588895149831017515102.029028339337623.26643910800.77202769.353365115.26545504.899637080.8992312.161834685.9038.45764.61700877.0238636746.24$187.0887720.30808191.8622015817617529652.19915577782.65582
5024200600120200259548347.568517306947194.00918606913.34478103193110147135518325837.289446241222510.29634171109.48212484.363309676.54608803.359374968.30103023.731770801.1642.91737.96713588.2640508922.04$187.2859410.30775192.1357175692635822315.08882784598.25802
5024200600120200372174139.327536372027194.00901031905.784681168112851143868422181631.3111433749992508.02622361078.73257690.603242484.48562293.619132879.8995153.201711796.9139.64713.35842024.1649150483.86$187.4669100.30733192.4801329853457955639.84843076265.93473
5024200600120200460591404.135105312323194.00886277391.26459733294741141125718599962.419587541991441.73612443600.40216448.403186074.11523514.798907487.2188590.921656861.9336.90690.43688979.6041302462.13$187.6358660.30697192.7808290617976487507.47809789883.7931
5024200600120200562521389.785773322272194.00871052909.08451082497758138295619168194.909880443353194.89602208363.93223467.533127867.95548336.788671407.7492791.381599322.2438.65666.43691552.3342661642.56$187.8129260.30659193.1028200435295559283.27775493625.81144
5024200600120200668227293.875043351683194.00854438991.454416422106681135207320887636.5310766747339657.34591037938.85244016.473064349.39664598.388385273.31112465.551529582.6646.85637.34728977.1046610680.24$188.0270730.30615193.46859036715116309760.23738129231.21234
5024200600120200761072008.883429310148196.91839567445.65433316994081132483718672400.909482642399607.99581039504.00215322.613008332.39544041.568151043.0992064.531472493.6938.35613.53633721.8641765886.13$191.0257550.30574193.75366773307136571246.86702996198.7963
5024200600120200868728532.076657349031196.91822831472.324239479105876129418620980803.1910654947747728.89569789373.09242482.462945292.89561370.627909352.0694997.011413586.3039.57588.96691365.0447056363.85$191.2096990.30527194.08787485569157340566.29665490906.03085
5024200600120200966809876.201728339288196.91806562707.764148404102920126439120362892.5510341146446983.65558856627.71235876.212884013.43612603.127645603.53103666.741349302.8443.18562.14648867.1045798116.56$191.4107790.30479194.42722175903177455940.14629106767.62242
5024200600120201058786557.812545298542196.91792247688.45406826790561123817517891643.839086140894913.98549240490.37207680.862830092.23537316.697414268.6290926.521292919.5437.87538.62553029.8140341884.17$191.5865290.30435194.73838215928195091401.13597156287.31721
5024200600120201165607942.905372333184196.91776271604.723978830101069120891619934214.5810123445673728.32538514449.90231950.102769914.17604679.427153931.54102325.871229467.5542.62512.16594685.8245079042.50$191.7841650.30384195.10044866155214696969.18561574635.54754
5024200600120201260595801.555906307730196.91761516019.40389622793348118189318381364.599334842214436.96528614335.32214382.252714333.72587798.936900862.1399469.301167786.9141.43486.43529008.2641685428.70$191.9768060.30334195.44962087179232729208.35528786811.05275