Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
MarcelPadu
Contributor
Contributor

data comparison with different date fields using max year

I have 2 tables with sales and dates that dont match (2022 in 1 date can be 2023 in the other). I want to display and maybe compare the values in the 2 tables  and still work with other selections such as region.

The tables i ve been working on however are line charts with 1 line for the current year and 1 line for the previous year, and they also show the last year by default such as:

Line1: sum({<Date1Year = {$(=max(Date1Year))}>} Sales1)
Line2: sum({<Date1Year = {$(=max(Date1Year)-1)}>} Sales1)

and the equivalent for the 2nd table with date2 and sales2.

Now, if I am to use this code to negate the effect of the other date field in the tables:

sum({<Date2Year =, Date1Year = {$(=max(Date1Year))}>} Sales1)

the problem is: if one client wants to compare data from a far back year and makes a selection on say 1900 in Date2Year and the year 1900 doesnt have a connection to the year 2023 in Date1Year, the table 1 will display wrong data  because the range of dates will be affected and now the max year for date 1 might be 1927 or something like that.

I understand maybe i should use alternate states but there are many factors to the data and to my understanding i ll have to introduce 2 region fields, 2 driver fields etc for each state.

Now, my solution was:

Line1: if(GetSelectedCount(date1year) = 0,
sum({<date2year=, date1year = {$(=year(today()))}>} Sales1),
sum({<date2year= >} Sales1)))

Line2: if(GetSelectedCount(date1year) = 0,
sum({<date2year=, date1year = {$(=year(today())-1)}>} Sales1))

and this works fine for the current year but i cannot display the previous year anymore once a date1year selection is made (id have to get the current selection and reduce the year by 1 which I cant easily make it work).

 

My final question is:
is there a simple way in which i can make any date2year selections not affect the results of the  sum({<Date2Year =, Date1Year = {$(=max(Date1Year))}>} Sales1) sintax?

I think i am making this way too complicated and the only solutions i can think of will make everything even more complex (such as add dummy lines that connect all date values to each other).

Labels (1)
1 Reply
MarcelPadu
Contributor
Contributor
Author

In the end I added another key in the 2 tables and inserted all dates that are going to be used under the key. Its a very nasty fix because it only fixes the selections when you have to deal with the 2 dates fields but if you have another selection on say region THAT TOO will reduce your range of values and affect the max(year) sintax, so now i have to go in all tables and map all the values of all selections on the said key, and also manualy remove the key from any fields that might count it.