Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
magellan
Contributor III
Contributor III

Do calculation if year in column is current year

Hello,

I have three columns with years, number of tickets and number of calls. 

Year Tickets Calls
2022 100 200
2023 200 300

 

Now I need an expression which sums up Tickets, Calls and divides them if the year is the same as the current year. I've tried this:

if($(vYear) = $(vYearToday),sum($(vTickets))/sum($(vCalls)))


vYear is the year field, behind vYearToday is the expression year(today()) and vTickets & vCalls are above columns.
But this doesn't work and result is '-'.

Is there any other way to achieve this?

Labels (2)
1 Solution

Accepted Solutions
steeefan
Luminary
Luminary

For me, both of these work:

 

If(Year = Year(Today()), Sum(Tickets)/Sum(Calls))

If($(vYear) = $(vYearToday), Sum($(vTickets))/Sum($(vCalls)))

 

steeefan_1-1703059835112.png

My variable defintions are:

steeefan_0-1703059738116.png

Why are you using variables instead of field names or master measures?

View solution in original post

3 Replies
steeefan
Luminary
Luminary

For me, both of these work:

 

If(Year = Year(Today()), Sum(Tickets)/Sum(Calls))

If($(vYear) = $(vYearToday), Sum($(vTickets))/Sum($(vCalls)))

 

steeefan_1-1703059835112.png

My variable defintions are:

steeefan_0-1703059738116.png

Why are you using variables instead of field names or master measures?

TcnCunha_M
Creator III
Creator III

you can use Set Analysis

vYear = Max(Year)

 

Then


sum({<Year =, Year ='$(vYear)'>} Tickets)
/
sum({<Year =, Year ='$(vYear)'>} Calls)

 

then it doesn't matter with year you select it will bring the calculation for it year selected

As you think, so shall you become.
Ahidhar
Creator III
Creator III

something like this ?

Ahidhar_0-1703065420757.png