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

Expression dependent on which tables fields' are filtered

Hi all,

I've been pondering this and exploring it for several days without quite figuring it out, and after pretty extensive exploration of the forums, I haven't yet found a clean solution, so I'm hoping y'all can help:

In an expression, I want to do one calculation if there are filters applied to any of the 145 fields that make up three of my tables (the fact and two of the dimensions).  I want a different calculation if there are not any filters on those fields (but there might be filters using fields in the remaining two tables). 

I've basically narrowed it down to two promising approaches, neither of which I can quite make work.

Option 1: Do my conditional switch between the two calculations based on wildmatching the Current Selections to the Field Names in the tables I care about.  Example:

wildmatch(GetCurrentSelections(),

   concat({< [$Table] =- {'FIRST_TABLE_TO_IGNORE','SECOND_TABLE_TO_IGNORE'}>} chr(39) & '*' & $Field & '*' & chr(39) ,',')) 

Both the GetCurrentSelections() and the concat statement seem to give what I would expect to work, and a baby example works fine:

Wildmatch(GetCurrentSelections(),'*State*','*Status*','*Attribute*')  // works fine

However, the overall wildmatch expression with the set analysis to get the fields does not work.  Is there a limitation on the number or length of the expressions to which wildmatch can compare?  My concat string is 2824 characters long with 145 expressions (field names) to test against. 

Option 2:  Somehow do a Get Selected Count on all the fields I care about and add them up and see if it's greater than 0.  Example:

sum( {'FIRST_TABLE_TO_IGNORE','SECOND_TABLE_TO_IGNORE'}>} GetSelectedCount($Field)  )

The problem with this seems to be that GetSelectedCount generally can't accept more than one field name at a time, or even the $Field system field in general. This is the closest prior attempt at this that I found:  Getselectedcount in multiple fields and it relies on the fields having similarly structured names; I'd rather not rename all my fields just to enable this one calculation to work.

Is there maybe some way to loop through all the $Field values in the set I want -- maybe something macro'y?  (Haven't played with the macros much yet...)

Thanks in advance for any advice you can give me on making either of these approaches work, or suggesting an option I haven't come up with yet!


Regards,

Emily

1 Solution

Accepted Solutions
Not applicable
Author

Update - I think I've gotten a variant on Option 1 to work.  The concat wasn't expanding properly within the wildmatch, I think. 

This seems to work:

& Wildmatch(GetCurrentSelections(),

   $(=concat({< [$Table] =- {'FIRST_TABLE_TO_IGNORE','SECOND_TABLE_TO_IGNORE'}>} chr(39) & '*' & $Field & '*' & chr(39) ,',')) )

View solution in original post

2 Replies
Not applicable
Author

Lost part of the Option 2 expression. It should be: 

sum( {< [$Table] =- {'FIRST_TABLE_TO_IGNORE','SECOND_TABLE_TO_IGNORE'}>} GetSelectedCount($Field)  )

Not applicable
Author

Update - I think I've gotten a variant on Option 1 to work.  The concat wasn't expanding properly within the wildmatch, I think. 

This seems to work:

& Wildmatch(GetCurrentSelections(),

   $(=concat({< [$Table] =- {'FIRST_TABLE_TO_IGNORE','SECOND_TABLE_TO_IGNORE'}>} chr(39) & '*' & $Field & '*' & chr(39) ,',')) )