Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Multiple values in set expression

Hi,

I have a variable, vYear=GetFieldSelections(Year) and a set expression using this variable -

Count({<Year={"$(=$(vYear))"}>}Distinct [Groups Key]).

The above set expression works when a single value is selected in the Year filter, but when I select multiple values in the filter the set expression returns null. Can anyone please guide me how to fix this expression ?

Appreciate your help !

Thanks,

Deepika

10 Replies
Gysbert_Wassenaar

If you want the selections in the field Year to be applied to the expression then you can use this expression:

Count(Distinct [Groups Key])


There's no need for set analysis because the selections you make are the same that you want to use for calculating the expression.


talk is cheap, supply exceeds demand
Not applicable
Author

Hi Gysbert,

Thanks for the response.

The chart where I am using the set expression uses a fact table which is linked to master calendar, but the Year filter is not referencing the Master calendar, but a different table not linked to the master calendar. This is the reason for the set expression.

Deepika

Gysbert_Wassenaar

That's not possible. You're using the field 'Year' in both the getfieldselections function and the count expression. You are using the same field 'Year' in both cases. So you get exactly the same selections.

There can only be one field 'Year' in the data model. If two or more tables have that same field 'Year' then those tables are linked. That's the way Qlikview works.


talk is cheap, supply exceeds demand
Not applicable
Author

Sorry, the set expression should have been like this - Count({<MC_Year={"$(=$(vYear))"}>}Distinct [Groups Key]).

saimahasan
Partner - Creator III
Partner - Creator III

Can you please post a sample application.

Anonymous
Not applicable
Author

Hi, try this:

vYear=CONCAT(DISTINCT Year,',')

Count({<Year={$(vYear)}>}Distinct [Groups Key])

Regards!!

Gysbert_Wassenaar

Ok, then try this one: Count({<MC_Year=$::Year>}Distinct [Groups Key])


talk is cheap, supply exceeds demand
lorenzoconforti
Specialist II
Specialist II

Hi

This drove me nuts too; I have implemented something similar in a dashboard I worked on recently

It's a two step approach as Manuel has indicated.

First, populate the variable and format it as per below (take note of ' and "); please note I had to assign * value for my expression to work when no Year was selected:

vYear=if(isnull(GetFieldSelections(Year)), '*', Replace(Replace(GetFieldSelections(Year),' ',''),',','","'))

Try use the following in your set expression:

=count({<Year = {"$(vYear)"}>} Distinct [Groups Key])

Hope it helps

Lorenzo

Anonymous
Not applicable
Author

Hi Lorenzo, with concat function you don't need to use *.

Regards!