Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
valkbart
Contributor
Contributor

Compare 'this period' to the 'same period' last year

I'm trying to build an expression that does the following

  1. Find the totals of this year (always starting from the 1st of January of the current year) ( Sum(Gross) )
  2. Find the totals of the same period last year (always starting from the 1st of January of the previous year till today's date one year ago)
  3. The expression should return an index where this year's totals are divided by last year's totals
  4. Ignore all date selections. If last year is selected, then I still want to get the above data for this year in comparison to last year


I have my current year in a variable v_CurrentYear and my previous year in a variable v_PreviousYear. Could someone please help me along with my expression? I'm stuck with all the '$', '#', '{' and '('...

5 Replies
Not applicable

What are the other relevant fields? Do you have a year field?

If you have a year field, then:

Sum({<Year={$(=v_CurrentYear)}>} Gross)
Last Year:
Sum({<Year={$(=v_CurrentYear-1)}>} Gross)


If your year field is a string, then you would need quotes. If you don't have a Year field, I would create one in the load, but the expression could be modified to be a between two dates.

To ignore a field, add it into the Set Analysis without an Element Set. For Date, it would be:

Sum({<Date=,Year={$(=v_CurrentYear)}>} Gross)


Year does not need to be ignored, because you are already modifying its value with the Set Analysis.

valkbart
Contributor
Contributor
Author

The problem with this expression is that it will return a Sum of ALL data from last year. I only want a SUM that returns me the data from last year starting from January 1st and then running to today's date MINUS one year.

So for today that would mean: 2010-01-01 till 2010-02-14

Not applicable

Then you need a modifier on date. Last year:

Sum({<Date={'<=$(=AddYears(Today(),-1))'},Year={$(=v_CurrentYear-1)}>} Gross)


You could also put two conditions on Date to define a span:

Sum({<Date={'>=$(=MakeDate(Year(Today())-1))<=$(=AddYears(Today(),-1))'}>} Gross)


rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Not applicable

you can solve this problem?? i have the same issue.

Help please, i stuck with this since 2 weeks and i haven´t a solution

Thanks