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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Luffy20
Contributor III
Contributor III

Count of a particular year

Hi all

I Have the following data

Country Year Vehicles
Australia 2024 65
India 2023 33
japan 2024 41
Itlay 2024 93
Germany 2024 22
Uk 2023 34
USA 2024 56

How can i get count of vehicles added in present year(2024)

can anyone help me with this

Labels (6)
1 Solution

Accepted Solutions
Qrishna
Master
Master

All the below would work:

=sum({$<Year={2024}>}Vehicles)
=sum({$<Year={"$(=max(Num(Year)))"}>}Vehicles)
=sum({$<Year={"$(=year(today()))"}>}Vehicles)

2493819 - Count of a particular year.PNG

View solution in original post

7 Replies
henrikalmen
Specialist II
Specialist II

Try this: sum({<Year={$(=year(today()))}>} Vehicle)

Muthukumar_77
Contributor III
Contributor III

Try this: sum({<Year={$(=Max(Year))}>} Vehicle)

Thanks Regards,
Muthukumar P
Qlik Developer
Luffy20
Contributor III
Contributor III
Author

It is showing the following error

The selections generated no data for this chart

henrikalmen
Specialist II
Specialist II

I'm just assuming that you have a field named Vehicle because it looks like it in the image you provided. But maybe you need to change that. And you could also try a simpler solution first, like a hard coded year: sum({<Year={2024}>} Vehicle)

Muthukumar_77
Contributor III
Contributor III

Hi,

Check the data type of Year field whether Numeric or Text format.

If it is text format, Use below expression

sum({<Year={$(=Max(Num#(Year,'####')))}>} Vehicle)

Thanks Regards,
Muthukumar P
Qlik Developer
henrikalmen
Specialist II
Specialist II

@Muthukumar_77 If it's text format, then that shouldn't work. Probably sum({<Year={'$(=Max(Num#(Year,'####')))'}>} Vehicle) could work (i.e. surround the formula with apostrophes to make it text).

But it's always easier to try hard coded solutions first (2024 or '2024') and then go for a dynamic solution. In this case, @Luffy20 hasn't said anything about what should happen if there is a selection active in the app. Let's say a user has filtered on year 2023 - should the result still be calculated for current year, or the selected year?

Qrishna
Master
Master

All the below would work:

=sum({$<Year={2024}>}Vehicles)
=sum({$<Year={"$(=max(Num(Year)))"}>}Vehicles)
=sum({$<Year={"$(=year(today()))"}>}Vehicles)

2493819 - Count of a particular year.PNG