Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
jeevays7
Partner - Creator III
Partner - Creator III

YTD based on date selection for each month in the year of selected date

Date               MonthYr         Value

30-Dec-2016  Dec-2016          100

1-Jan-2017     Jan-2017          10

3-Jan-2017     Jan-2017          11

1-Feb-2017     Feb-2017          20

10-Feb-2017    Feb-2017         30

1-Mar-2017     Mar-2017          60


The above is my data and i need,

If i select a date i.e. 1-Feb-2017, the result should show value from year start  to end of the month of selected date.

result should be like below,


MonthYr     Sum(Value)

Jan-2017     21

Feb-2017     50


and if i select a date i.e 30-Dec-2016 the result will be,

MonthYr     Sum(Value)

Dec-2016     100

1 Solution

Accepted Solutions
sunny_talwar

Two ways to do this

1) Use this expression (this will assume that your data is sorted by MonthYear in ascending order in the script)

=Aggr(RangeSum(Above(Sum(Sales), 0, RowNo())), Year, MonthYear)

2) Create another field called MonthNum in the script

LOAD Year as Date,

  MonthName(Year) as MonthYear,

  Year(Year) as Year,

    Sales,

    Product,

    Num(Month(Year)) as MonthNum

FROM

[Month on Month.xls]

(biff, embedded labels, table is Sheet1$);

Which will look like this:

Capture.PNG

and then use this expression:

=RangeSum(Above(TOTAL Sum(Sales), 0, MonthNum))

Capture.PNG

View solution in original post

11 Replies
sunny_talwar

May be this:

Sum({<Date = {"$(='>=' & Date(YearStart(Max(Date)), 'D-MMM-YYYY') & '<=' & Date(Max(Date), 'D-MMM-YYYY'))"}, MonthYr>} Value)

sunny_talwar

Just make sure that QlikView read your date as a dual field and not a text. Look here for help on these topic

Why don’t my dates work?

QlikView Date fields

Get the Dates Right

Dates in Set Analysis

jeevays7
Partner - Creator III
Partner - Creator III
Author

Hi sunny,

Thanks for your reply. it is working for maximum month(selected date) only, it doesn't work for other month.

sunny_talwar

Where are you making selection MonthYr field or do you have another field? Please share a sample where this isn't working for you

jeevays7
Partner - Creator III
Partner - Creator III
Author

Hi Sunny,

Im selecting date field. not MonthYr

jeevays7
Partner - Creator III
Partner - Creator III
Author

Hi Sunny,

My Selection is date field.Here i attached the sample file.

I need output like this

      

MonthYearYearSalesOutputExplanation
Jan 20112011300300300
Feb 20112011200500300+200=500
Mar 201120115001000500+500=1000
Apr 2011201120012001000+200=1200
May 201120116001800
Jun 201120112002000
Jul 201120113002300
Aug 201120114002700
Sep 201120111002800
Oct 201120112003000
Nov 201120113003300
Dec 201120114003700
Jan 20122012100100Reset pointYear start so no need to add previous month value
Feb 20122012100200
Mar 20122012300500
Apr 20122012400900
May 201220121001000
Jun 201220122001200
Jul 201220123001500
Aug 201220124001900
Sep 201220121002000
Oct 201220122002200
Nov 201220123002500
Dec 201220124002900
Jan 201320136060Reset point
Feb 20132013120180
sunny_talwar

Two ways to do this

1) Use this expression (this will assume that your data is sorted by MonthYear in ascending order in the script)

=Aggr(RangeSum(Above(Sum(Sales), 0, RowNo())), Year, MonthYear)

2) Create another field called MonthNum in the script

LOAD Year as Date,

  MonthName(Year) as MonthYear,

  Year(Year) as Year,

    Sales,

    Product,

    Num(Month(Year)) as MonthNum

FROM

[Month on Month.xls]

(biff, embedded labels, table is Sheet1$);

Which will look like this:

Capture.PNG

and then use this expression:

=RangeSum(Above(TOTAL Sum(Sales), 0, MonthNum))

Capture.PNG

sunny_talwar

Updated the expressions to make sure they work even when you make selections

1) =Aggr(RangeSum(Above(Sum({<Date, MonthYear, Year>}Sales), 0, RowNo())), Year, MonthYear)

2) =RangeSum(Above(TOTAL Sum({<Date, MonthYear, Year>}Sales), 0, MonthNum)) * Avg(1)

jeevays7
Partner - Creator III
Partner - Creator III
Author

Hi Sunny,

Thank you very much. it working now.

but if i do the same thing in pivot table how to use

this sunny.

RangeSum(Above(Sum(Sales), 0, MonthNum))


this exp is not working on pivot table.