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: 
rahulsingh12
Contributor III
Contributor III

YTD In Qlikview

Hi,

I have two fields year and month as text.

I want to calculate YTD for current selected Month by the user.

Thus if the user selects jan it should give sum of sales for Jan only if they select Feb they should get for Jan and feb and hence forth.

I wrote the following code:

sum({<MonthYear={">=$(=vMinYearMonth)<=$(=vMaxYearMonth)"}>}[Volume])

I created a field YearMonth by converting Month into numbers and concatenating with Year.

Thus vminyearmonth is min YearMonth for any selected Month,similary vMaxYearMonth is max of YearMonth  for any selected yearmonth(In this case the selected month).

But the sum I get is only for the selected month not YTD.

what is it that I am doing wrong.


Regards.

7 Replies
Anonymous
Not applicable

Hello Rahul,

Try This,

     Sum({<Year=, Month=, Quarter=, Week=, DateField=, DateNum={">=$(=Num(YearStart(Max(DateNum))))<=$(=Max(DateNum))"}>} Sales)

Anonymous
Not applicable

You should take a look in this post:

YTQ, QTD, MTD and WTD

prat1507
Specialist
Specialist

Hi

Since you want YTD values, for ex. if you select Feb, you must have the sum for Jan,Feb. Since this is the intent, your vMinYearMonth should not depend on the selected month and must be fixed.

Since you haven't fixed it, when you select Feb, it selects both vMinYearMonth and vMaxYearMonth as Feb for the selected year and similarly for any other selected month.


Just add Month= in your vMinYearMonth  set analysis expression.


I hope this would work.


Regards
Pratyush

rahulsingh12
Contributor III
Contributor III
Author

Hi Pratyush,

I have tried that.

But it doesnt seem to work.

Regards,

Rahul

Anil_Babu_Samineni

We need variable definition too, Because vMinYearMonth need to be calculated like YearStart(Min(Year))

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
rahulsingh12
Contributor III
Contributor III
Author

It is working.

can you tell me how will I last year YTD for same selected month and year?

Regards,

Rahul

Anil_Babu_Samineni

Like this?

YearStart(AddYears(Today(),-1))

Month(AddYears(Today(),-1))

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