Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Louveduval
Creator
Creator

Why the date comparaison doesn't work ?

Hello, 

I don't unsterdant why it doesn't work 

if ( [AnnéeMois2] > '31/12/2022',

(RangeSum(above(If([Unité de commande] = 'pièce', Sum( {< Année={"$(=YearName(Max(Date)))"}>} [m3/ pièce]* [QTÉ CMDE]), Sum({< Année={"$(=YearName(Max(Date)))"}>} [QTÉ CMDE])),0,RowNo(Total))))
,
(RangeSum(above(If([Unité de commande] = 'pièce', Sum( {< Année={"$(=YearName(Max(Date),-1))"}>} [m3/ pièce]* [QTÉ CMDE]), Sum({< Année={"$(=YearName(Max(Date),-1))"}>} [QTÉ CMDE])),0,RowNo(Total)))
))
It's OK 

Louveduval_0-1689166465150.png

if ( [AnnéeMois2] > YearEnd(max([AnnéeMois2]),-1),
(RangeSum(above(If([Unité de commande] = 'pièce', Sum( {< Année={"$(=YearName(Max(Date)))"}>} [m3/ pièce]* [QTÉ CMDE]), Sum({< Année={"$(=YearName(Max(Date)))"}>} [QTÉ CMDE])),0,RowNo(Total))))
,
(RangeSum(above(If([Unité de commande] = 'pièce', Sum( {< Année={"$(=YearName(Max(Date),-1))"}>} [m3/ pièce]* [QTÉ CMDE]), Sum({< Année={"$(=YearName(Max(Date),-1))"}>} [QTÉ CMDE])),0,RowNo(Total)))
))
It's not OK

Louveduval_1-1689166573713.png

But  YearEnd(max([AnnéeMois2]),-1) = 

Louveduval_2-1689166816049.png

Labels (3)
1 Solution

Accepted Solutions
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi there!

To understand the issue, you should understand that your expression is being evaluated in the context of your chart dimensions. It looks like your chart dimension is related to dates - either a date, or a week, or a month... For each value of that dimension, the max(year) will be potentially different, hence the issue.

You can try one of the two solutions:

1. You can add the keyword TOTAL to your YearEnd calculation:
        if ( [AnnéeMois2] > YearEnd(max( TOTAL [AnnéeMois2]),-1), ...

and that should disregard the impact of dimensionality

2. Or, you can pre-calculate the desired value in a variable. Create a variable with the following definition:

         vYearEnd1 = "=YearEnd(max( TOTAL [AnnéeMois2]),-1)"

That will get calculated once, outside of your chart, and then in the chart expression, you can use it like this:

        if ( [AnnéeMois2] > '$(vYearEnd1 )', ...

Both solutions should work. The first is easier to implement, while the second could improve performance, if that's a concern. Good luck!

To learn more advanced development techniques, check out the agenda of the Masters Summit for Qlik - coming soon to Orlando and to Dublin!

View solution in original post

2 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi there!

To understand the issue, you should understand that your expression is being evaluated in the context of your chart dimensions. It looks like your chart dimension is related to dates - either a date, or a week, or a month... For each value of that dimension, the max(year) will be potentially different, hence the issue.

You can try one of the two solutions:

1. You can add the keyword TOTAL to your YearEnd calculation:
        if ( [AnnéeMois2] > YearEnd(max( TOTAL [AnnéeMois2]),-1), ...

and that should disregard the impact of dimensionality

2. Or, you can pre-calculate the desired value in a variable. Create a variable with the following definition:

         vYearEnd1 = "=YearEnd(max( TOTAL [AnnéeMois2]),-1)"

That will get calculated once, outside of your chart, and then in the chart expression, you can use it like this:

        if ( [AnnéeMois2] > '$(vYearEnd1 )', ...

Both solutions should work. The first is easier to implement, while the second could improve performance, if that's a concern. Good luck!

To learn more advanced development techniques, check out the agenda of the Masters Summit for Qlik - coming soon to Orlando and to Dublin!

Louveduval
Creator
Creator
Author

You're so strong , thank you very much !!!