Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Is there an easy way to get the names of fields with selections?

I know about GetCurrentSelections. What I need, however, is a way to generate an output that only contains the names of the fields in which a selection is currently made. Is there an easy way to achieve this?
The only idea I have so far is to work with string functions and to somehow reduce the text to only the field names.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Jason,

I believe the 2-parameter version of subfield won't work in the frontend, so your expression will only return one field name, not all selected.

Susann,

I don't know if there is an easy way of getting just the names of fields with selected values, maybe I am just missing the right QV function. I assume you want to get your results as string in any chart object, not just using the current selections box and disable the visibility of the values, dropdown and clear symbol (in general tab).

I could think of two different 'general' approaches to create such a string, i.e. we don't want to hardcode the field names and the check on any selections in them, but we want to be flexible (allowing more fields to be added). If hardcoding is not a problem, I think we can just create an expression like

=if(GetSelectedCount(Field1),'Field1 ') & if(GetSelectedCount(Field2),'Field2 ')

(adding all fields to the expression).

The first general approach might automatically create kind of this expression as a variable in the script, maybe using a loop over all fields or a concat technique (which I haven't fully in mind yet).

The second general approach I can think of involves the use of subfield functions again and a technique to create an iterator for the third parameter. We can do it like this:

=concat(subfield(subfield(GetCurrentSelections('/'),'/',ValueLoop(1,vFieldNum,1)),':',1),', ',ValueLoop(1,vFieldNum,1))

The important thing here is the ValueLoop function, which creates a loop for us when used in an aggregation function like concat, the valueloop function acts as an iterator. vFieldNum is a variable that just holds the number of fields (=count($Field) )

See also attached.

Hope this helps,

Stefan

View solution in original post

8 Replies
sivarajs
Specialist II
Specialist II

Hi,

Create a Variable and use getcurrentselections

U will get only selected values

Sivaraj S

Not applicable
Author

Thanks for your answer.
But using a variable does exactly the same as if I just use the function and print the results (e.g. in a textbox).
I do, however, only need the names of the fields where selections are made. I do not want to also get the selected values.
For example if I had the fields date, product, country and type and select only a date and a country, if I use GetCurrentSelections() I get
Date: 10/04/2000
Country: England
as an output. What I want to achieve is that I only get
Date
Country
as output.

sivarajs
Specialist II
Specialist II

Try this..

=SubField(GetCurrentSelections(date),':',1)

Jason_Michaelides
Luminary Alumni
Luminary Alumni

Using a nested Subfield() statement and GetCurrentSelections() I think you can achieve this:

=SubField(SubField(GetCurrentSelections(';',':'),';'),':',1)

Should work...but will only be good for a chart object or list box, I think. If you want a single text string for a text box or similar then try surrounding the above in a Concat() statement. 

Hope this helps,

Jason

swuehl
MVP
MVP

Jason,

I believe the 2-parameter version of subfield won't work in the frontend, so your expression will only return one field name, not all selected.

Susann,

I don't know if there is an easy way of getting just the names of fields with selected values, maybe I am just missing the right QV function. I assume you want to get your results as string in any chart object, not just using the current selections box and disable the visibility of the values, dropdown and clear symbol (in general tab).

I could think of two different 'general' approaches to create such a string, i.e. we don't want to hardcode the field names and the check on any selections in them, but we want to be flexible (allowing more fields to be added). If hardcoding is not a problem, I think we can just create an expression like

=if(GetSelectedCount(Field1),'Field1 ') & if(GetSelectedCount(Field2),'Field2 ')

(adding all fields to the expression).

The first general approach might automatically create kind of this expression as a variable in the script, maybe using a loop over all fields or a concat technique (which I haven't fully in mind yet).

The second general approach I can think of involves the use of subfield functions again and a technique to create an iterator for the third parameter. We can do it like this:

=concat(subfield(subfield(GetCurrentSelections('/'),'/',ValueLoop(1,vFieldNum,1)),':',1),', ',ValueLoop(1,vFieldNum,1))

The important thing here is the ValueLoop function, which creates a loop for us when used in an aggregation function like concat, the valueloop function acts as an iterator. vFieldNum is a variable that just holds the number of fields (=count($Field) )

See also attached.

Hope this helps,

Stefan

Jason_Michaelides
Luminary Alumni
Luminary Alumni

Another fantastic use for the little-known ValueLoop Stefan!  Nice one

colinodonnel
Creator II
Creator II

Still a valid solution 10 years later (and perhaps for another 10 years more?)

Just change a number to keep the fieldvalues instead of the fieldnames 

e.g. England, France, Germany instead of the original Country: England, France, Germany when just using GetCurrentSelections() on its own

=concat(subfield(subfield(GetCurrentSelections('/'),'/',ValueLoop(1,vFieldNum,1)),':',2),', ',ValueLoop(1,vFieldNum,1))

juan_c_martinez
Contributor III
Contributor III

Thanks Swuehl, especially for showing the use of Vloop.  I was looking for a funcition to exclude some selecction fileds in a setanalysis, it was useful for me. 

A lite bit more portable:

= concat( subfield(
subfield( GetCurrentSelections('/') ,'/' , ValueLoop(1,$(=count($Field)),1)),':',1),', ',ValueLoop(1,$(=count($Field)),1)
)