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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
akhwaja1
Contributor
Contributor

Set analysis using Year and/or month

I have a set of top-level metric that counts the number of units wholesaled  or final delivered in a given month - 

=num(count ({$<[wholesale_month]*=[i_month],[wholesale_year]*=[i_year]>} unit),'#,##0')
=num(count({$<[fd_month] *=[i_month],[fd_year] *=[i_year]>}[unit]),'#,##0')

 I govern the selection of year and month using list boxes tied to i_year and i_month as shown in the image. 

akhwaja1_0-1609360973676.png

This works. 

However, if only the year is selected and nothing in month, the metrics show 0. How do I extend the metric expressions so that I get a yearly value if the year is selected and a monthly value if both year and month are selected?

 

Labels (1)
1 Reply
QFabian
MVP
MVP

Hi @akhwaja1 , you can create a variable like this :

vi_month = max(i_month)

then use it in your expression :

=num(count ({$<[wholesale_month]*=[$(vi_month)],[wholesale_year]*=[i_year]>} unit),'#,##0')

 

so if there is no selection over month, or of the user select two o more values over month  its going to take the max month

 

 

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.