5 Replies Latest reply: Jan 31, 2010 5:01 PM by Angelos Vlisidis RSS

    YTD Calculation in a Straight Table

      I am trying to calculate the YTD amount in a straight table where my time dimension is the rows (see table below). I cannot use any of the "Accumulation" methods due to issues with combining calculations on data that does not require accumulation (Balance Sheet vs Income Statement Accounts).

      I don't want to use a date selection because it needs to calculate for every date in the table. Any time I use a set analysis on my Period field (i.e. Period = {'>= yearstart(Period)'} ) I just get the calculation for the current month and not a YTD number. I can only find examples where the date is not a dimension and/or someone is selecting the date. I can do that, I just can't find the right code for this.

      Convert column 'B' below to Column 'C'.

      Thanks in advance for your help,

       

      PeriodCurrent MonthYTD Calc
      (How in QV?)
      NET INCREASE IN CASHPrev YTDEnding Cash Calc
      ABCDEF
      Jan08(8,518,694)-8,518,6944,470,93800
      Feb08207,532-8,311,161-207,5328,518,6948,311,161
      Mar08701,159-7,610,002-701,1598,311,1617,402,470
      Apr08(262,333)-7,872,336262,3337,610,0026,963,644
      May08(402,577)-8,274,913402,5777,872,3367,628,555
      Jun08(272,945)-8,547,858274,6328,274,9138,305,764
      Jul08(172,186)-8,720,043172,1868,547,8588,750,895
      Aug0844,980-8,675,064-44,3788,720,0438,878,702
      Sep08(728,669)-9,403,733728,6698,675,0649,562,392
      Oct08457,146-8,946,587-457,1469,403,7339,833,915
      Nov081,254,003-7,692,584-1,261,7278,946,5878,115,042
      Dec08757,008-6,935,576-727,1467,692,5846,133,893
      Jan09231,979-6,703,5973,444,2756,935,5768,821,160
      Feb09(6,008)-6,709,605-196,4616,703,5978,600,253
      Mar09129,475-6,580,129-830,6346,709,6058,476,785
      Apr09442,578-6,137,551-182,2016,580,1297,902,775
      May09831,617-5,305,935-351,3066,137,5516,706,315
      Jun09455,698-4,850,237-180,3825,305,9355,419,684
      Jul09110,261-4,739,97664,6934,850,2374,856,493
      Aug09214,921-4,525,055-259,9014,739,9764,530,710
      Sep09257,189-4,267,866473,9354,525,0554,061,055
      Oct09(457,146)-4,725,01104,267,8664,261,011
      Nov09(1,254,003)-5,979,01404,725,0115,979,884
      Dec09(757,008)-6,736,02305,979,0147,961,033


        • YTD Calculation in a Straight Table
          Neil Miller

          Can you use Above()?

          If(Above([Current Month]), Above([YTD Calc]) + [Current Month], [Current Month])


          This expression is called YTD Calc, if you want to use a different label, you need to change Above([YTD Calc]) in the expression to reflect your YTD expression label.

            • YTD Calculation in a Straight Table

              I tried the Above() function and it just gives me the sum of the previous month plus the current month. It does not roll forward. In my table, the [YTD Calc] column is the formula that I need, so I do not have anything to substitute in your example. That is the missing formula I can't seem to figure out without using the "Accumulation" function.

              • YTD Calculation in a Straight Table

                I figured it out. After much searching and trying various topics, I used a combination of the rangesum and above functions. Here is what I got to work:

                =Rangesum(Above(sum([Actual]),0,Num(Month(Period))))

                where the above function allows you to choose how many row backs to start - in this case zero (0). Then I use my Period to tell it how many rows back to go (Num(Month(Period)). This way, when you get to a new year, it will automatically only go back one month and not carry a balance forward from last year (since Num(Month(Period)) = 1).

                This will overcome any issues with the "Full Accumulation" options in a table when you have multiple years.

                Thanks for the help.

                 

                 

                 



                 



                 

                 

                  • YTD Calculation in a Straight Table
                    Angelos Vlisidis

                    Hello to all,

                    I have the same problem with YTD calculations. The solution proposed by Kevin works fine only when month is the last (or the only) level in the chart. In my case below Month there is Week and Day Level. When Week&Day are collapsed everything is OK. When I expand a month to go to the week level the function returns the sum([Actual]).

                    I cannot believe that is so difficult to do a simple multivelel YTD in qlik.

                     

                     

                      • YTD Calculation in a Straight Table
                        Angelos Vlisidis

                        I found a workaround to this problem by using dimensionality() function thanks to http://community.qlik.com/forums/t/25153.aspx.

                        I have a pivot table with Market-Month-Week-Day dimensions. When everything is collapsed dimensionality() returns 1. When Market is expanded to Months returns 2 e.t.c

                        so the solution is:

                         


                        if (dimensionality() = 2, //MONTH LEVEL
                        rangesum(above(sum(CY_AMOUNT),0,MONTH)),
                        if(dimensionality() = 3, //WEEK LEVEL
                        rangesum(above(sum(CY_AMOUNT),0,WEEK)),
                        if(dimensionality() = 4, //DAY LEVEL
                        rangesum(above(sum(CY_AMOUNT),0,MONTH_DAY)),
                        sum(CY_AMOUNT) //Market Level
                        )
                        )
                        )


                         

                        I don't know what the performace penalty is but it works at least!

                        I am looking now to find a more elegant solution by using set analysis.