Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
francis_gr
Creator
Creator

last two years in a chart

Hi!!

How can I show in a chart, by default, the last two years? (only in this chart) Year is a dimension and i can select the years in a

list box.

I appreciate any help

Regards

Labels (1)
1 Solution

Accepted Solutions
swuehl
Champion III
Champion III

What do you mean with 'by default'? Should a selection in Year show the default or the selected years? Or any other condition?

Try maybe an expression in your chart like

=If(GetSelectedCount(YearField),

     Sum(Value),

     Sum({<YearField = {$(=Max(YearField)),$(=Max(YearField)-1)}>} Value)

)

The second Sum() uses Set Analysis to create a specific Year filter for the last two years.

View solution in original post

5 Replies
swuehl
Champion III
Champion III

What do you mean with 'by default'? Should a selection in Year show the default or the selected years? Or any other condition?

Try maybe an expression in your chart like

=If(GetSelectedCount(YearField),

     Sum(Value),

     Sum({<YearField = {$(=Max(YearField)),$(=Max(YearField)-1)}>} Value)

)

The second Sum() uses Set Analysis to create a specific Year filter for the last two years.

francis_gr
Creator
Creator
Author

Hi Stefan!

Thanks for your reply.

Your expression is perfect and solves my question, but, abusing a little of your patience, I would need to know what would be the expression to show on the same chart, for the selected years , the average of "val" field por the people with the same "Pto" field

Sincerely thanks for your help.

Please, see my attached file

swuehl
Champion III
Champion III

Maybe something like

=If(GetSelectedCount(Year),

      Avg(

      Aggr(

      Avg(total<Year,Pto> Val)

    , Year, Pto,Num)),

    Avg({<Year = {$(=Max(Year)),$(=Max(Year)-1)}>}

      Aggr(

      Avg({<Year = {$(=Max(Year)),$(=Max(Year)-1)}>}  total<Year,Pto> Val) // Count({<Year = {$(=Max(Year)),$(=Max(Year)-1)}>} DISTINCT Num)

    , Year, Pto,Num))

)

But if you want to add this as another expression in your existing line chart with already existing two dimensions, this will not really work well, I think. But it should work in a table chart or if you use the expression as part of your line chart expression (for example as denominator to normalize your values per person).

francis_gr
Creator
Creator
Author

Ok Stefan! That’s pretty close.

Just need that for the year(s) selected, if I select a name , line chart shows the selected person and the average val of all persons with the same job (pto field).

If I select a “pto” it must show all persons with the same “pto” and the average “val” for all of them.

Thanks for your suday time.

Regards

fema3773
Contributor II
Contributor II

I got this to work perfectly except when I need to add a second condition.  It shows no data to display.  This is what I am trying to use:

=If(GetSelectedCount(Year),

Count({<[Cause (MIDAS)] = {'Communication failures'}>}[MIDAS Record ID]),

Count({<Year = {$(=Max(Year)),$(=Max(Year)-1)>} {<[Cause (MIDAS)] = {'Communication failures'}>[MIDAS Record ID]>))

Do you know how to fix so I can default to the past two years for only records that have a Cause[MIDAS] that = Communication Failure?