Display Only Unique Options in a List - Greg Collins

InfoPath Dev

This Blog


Greg Collins

Display Only Unique Options in a List

When list box entries are looked up in either the form's data source or a data connection, you might end up with the user being presented duplicate options. You can correct this, and display only unique options in a list, by using a filter and the appropriate XPath.

In this task we will create a filtered drop-down list box that presents the user with a unique set of options. Let's start by designing a new blank form.

Add the controls to the view:

  1. Open the Controls task pane.
  2. Insert a Drop-Down List Box into the view.
  3. Insert a 1 column Repeating Table into the view.
  4. Type Source Values into the header row of the repeating table.

Populate the drop-down list box:

  1. Double-click the drop-down list box.
  2. On the Data tab of the Drop-Down List Box Properties dialog box, select Look Up Values In The Form's Data Source.
  3. Click the Select XPath button to the right of the Entries text box, and then select group1/group2/field2.

Filter for unique values:

  1. Click Filter Data, and then click Add.
  2. In the Specify Filter Conditions dialog box, select The Expression from the first drop-down list, and then type the following expression (as shown in Figure 1):

not(. = ../preceding::my:group2/my:field2)

Figure 1. Filtering list options to display only unique values.

  1. Click OK four times.

Try it:

Preview the form. Add several rows of values to the repeating table, making sure that some of the values are duplicates, and then examine the options in the drop-down list. As shown in Figure 2, the drop-down list only displays unique values as the XPath expression prevented duplicate values from being added to the list.

Figure 2. The filtered list box displays only unique options.

InfoPath applies our filter as it steps through the values in repeating table to add them to the list box entries. The XPath expression in our filter checks to see whether a my:field2 value in a previous row (my:group2) is identical to the my:field2 value in the current row. If it is, the value is not added to the list.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.



zaphi said:

Hi Greg

Sorry, but I have done exactly this sampler like explained, but I get duplicates in the list.

I have infoPath 2003 SP2, and work in german.

Can you explain it?

Best regards.


November 30, 2007 7:45 AM

zaphi said:

Hi Greg

Sorry, I had a problem with the german syntax. I could correct it, and it works correctly.

Your how-to is very good!

Best regards.


December 3, 2007 12:46 AM

Greg Collins said:

Thank you zaphi, I'm glad to hear you got it working!

January 15, 2008 9:53 AM

Lalato said:

Will this same logic work for a secondary data source?  I would like to do this with an XML file, but I keep getting duplicates.



April 14, 2008 10:05 AM

Lalato said:

Never mind... I figured out my problem.  Thanks for the great info.


April 14, 2008 10:08 AM

rab2k said:

Greg - Could you provide the syntax for pulling unique values from a SharePoint list?  I am using a Sharepoint List with duplicate values to populate the InfoPath Sharepoint dropdown, but would like it to only display unique values.  

July 7, 2008 10:26 PM

dave_2k8 said:

rab2k - Did you ever find a solution to you issue with pulling unique values from a SharePoint list.

I am looking to do the same - but cannot find a way to do it.


December 11, 2008 3:12 AM

rhallock said:

For a Secondary Data Source, the steps are the same but your XPath will look a bit different.

For example, my secondary data source looks like the following:


For the filter expression, my XPath looks like this:

not(. = ../preceding::dfs:Program_Fee_Reports/@Partner)

January 21, 2009 2:44 PM

granack said:

I'm having a problem with the filter including all of the values.  I'm using the following from a secondary data source:

not(. = ../preceding::dfs:_18-740-886-402_pg14/@kV)

I also have an additional condition that the name from the Main data source match the name from the secondary (sharepoint list)  (i.e. BreakerSelection is equal to Type1).  This is in order to determine which kV data to return to the list

The data I am testing for this filter is 4.76, 8.25, 8.25, 8.25, 15, 15, 15, 15, 15, 15, 15

The filter only returns 8.25 and 15 for the dropdown, why is it not including 4.76 since it is itself a unique value?

May 5, 2009 1:59 PM

rhallock said:

If you haven't figured this out, I'd start by removing the additional condition you have to see if it's the problem.

May 13, 2009 9:17 AM

Mel Balsamo said:

When designing an InfoPath form that integrates with a secondary data source such as a SharePoint list

October 16, 2011 2:15 PM

Elmholt said:


I need a filter like this on my dropdown list, but i am not sure how to define the expression

not(. = ../preceding::my:group2/my:field2)

What does "my:group2" and "my:field2" refer to?

December 13, 2011 7:28 AM

Crazymaca69 said:

Hi can anyone tell me how to do this when using an xml source?

Im having to use an xml source to be allow dynamic pictures from a picture library on Sharepoint. I had it working using a normal Sharepoint list but can't figure out what the string should be for xml?

December 5, 2014 9:36 AM
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.