Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Ciara
Creator
Creator

GetFieldSelections

I'm trying to find the correct syntax to use with GetFieldSelections. 

My code is below.

If(GetFieldSelections(DayFlag)='AM Only', Count({<DayFlag={'AM Only'}>}Distinct OR_Date),
       If(GetFieldSelections(DayFlag)='PM Only', Count({<DayFlag={'PM Only'}>}Distinct OR_Date),
              If(GetFieldSelections(DayFlag)='All Day', Count({<DayFlag={'All Day'}>}Distinct OR_Date),
                     If(GetFieldSelections(DayFlag)='AM Only' and GetFieldSelections(DayFlag)='All Day', Count({<DayFlag={'AM Only'}>}Distinct OR_Date)+Count({<DayFlag={'All Day'}>}Distinct OR_Date)))))

What I want to find is if the DayFlag chosen is 'AM Only' AND 'All Day' then do this...

1 Solution

Accepted Solutions
tresesco
MVP
MVP

That is fine. But it seems that your data model is connected since you are using the same flag field in set analysis. If you select a value from your flag field, qlik associative engine itself would filter the data accordingly. I am not sure if am missing anything here. Try using the expression I suggested and keep selecting different flag  values - you should get what you need. Otherwise, to answer your very question try like:

If(GetFieldSelections(DayFlag)='AM Only, All Day', Count({<DayFlag={'AM Only', 'All Day'}>}Distinct OR_Date)

If you select two or more values, getfieldselections() would return them separated by a comma and a space. Also note, you don't need two counts for two values, you can pass multiple values in one set analysis like shown above.

View solution in original post

4 Replies
tresesco
MVP
MVP

Why do you need separate expression for all the flag selections, especially when you are writing to calculate the same value as would have been in default expression without set analysis?

Did you try:

Count(Distinct OR_Date)

 ?

Ciara
Creator
Creator
Author

Because the same OR_Date might have an AM Only and a PM Only or an All Day flag.

tresesco
MVP
MVP

That is fine. But it seems that your data model is connected since you are using the same flag field in set analysis. If you select a value from your flag field, qlik associative engine itself would filter the data accordingly. I am not sure if am missing anything here. Try using the expression I suggested and keep selecting different flag  values - you should get what you need. Otherwise, to answer your very question try like:

If(GetFieldSelections(DayFlag)='AM Only, All Day', Count({<DayFlag={'AM Only', 'All Day'}>}Distinct OR_Date)

If you select two or more values, getfieldselections() would return them separated by a comma and a space. Also note, you don't need two counts for two values, you can pass multiple values in one set analysis like shown above.

Ciara
Creator
Creator
Author

Hey Tresesco

Thanks for the tips but unfortunately I have to do 2 separate counts due to the possibility of an OR_Date having any or all 3 of the flags.

When I used your logic below it worked perfectly, but I wanted to extend it then to all other possibilities (If 'All Day' and 'PM Only' were chosen do this.... but it didn't work.