Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

businessintelli
New Contributor III

Current Year (Sum)

I use this formula to calculate sum for the current year. .

if(GetSelectedCount ([Month])> 0 or GetSelectedCount(Year)> 0, Sum([g.SellingAmount]), Sum ({<Date = P({<Year={$(=max(Year(today())))}>}Date)>}[g.SellingAmount]))

The field g.sellingAmount has different values and how can I change this formula to access only one of them. I want to calculate the sum for the current year only for one of them..

1 Solution

Accepted Solutions
karthikoffi27se
Contributor III

Re: Current Year (Sum)

You can use Name1 inside your set analysis

if(GetSelectedCount ([Month])> 0 or GetSelectedCount(Year)> 0, Sum([g.SellingAmount]), Sum ({<Name1={*},Date = P({<Year={$(=max(Year(today())))}>}Date)>}[g.SellingAmount]))


this will caluclate for name 1 column's too.


Many Thanks

Karthik

4 Replies
devarasu07
Honored Contributor II

Re: Current Year (Sum)

Hi,

try below method,

u can simply try to use set analysis expression like below

Sum ({$<Year ={"$(=Max(Year))"} >} [g.SellingAmount])

or

u can try to add current year YTD flag in your calendar script


LET vMinDate = num(Peek('MinDate'));

LET vMaxDate = num(Peek('MaxDate'));

LET vToday = vMaxDate;

InYearToDate(CalDate,$(vToday),0) * -1 as CurrYTDFlag,

InYearToDate(CalDate,$(vToday),-1) * -1 as LastYTDFlag,

then u can use it

Sum ({$<CurrYTDFlag={1} >} [g.SellingAmount])


Thanks,Deva

businessintelli
New Contributor III

Re: Current Year (Sum)

Thank you for your help.

but I have a different question. 

For example, in this field we have 'Name1', 'Name2', 'Name3','Name4',columns and I want to calculate only for 'Name1''s sum for the current year.


In this formula, all values are calculated. and I want to change this in such way to show only one of them.

if(GetSelectedCount ([Month])> 0 or GetSelectedCount(Year)> 0, Sum([g.SellingAmount]), Sum ({<Date = P({<Year={$(=max(Year(today())))}>}Date)>}[g.SellingAmount]))

karthikoffi27se
Contributor III

Re: Current Year (Sum)

You can use Name1 inside your set analysis

if(GetSelectedCount ([Month])> 0 or GetSelectedCount(Year)> 0, Sum([g.SellingAmount]), Sum ({<Name1={*},Date = P({<Year={$(=max(Year(today())))}>}Date)>}[g.SellingAmount]))


this will caluclate for name 1 column's too.


Many Thanks

Karthik

businessintelli
New Contributor III

Re: Current Year (Sum)

Thank you very much    It works

Community Browser