cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Avoid duplicate entries in a gallery

Hello,

 

i have a gallery from a collection with users and their parameter. a user can exist several times with different parameters. I would like to show the user only once, i can then look at its parameters in the details Form.

 

My code in Gallery Items

 

SortByColumns(
    If(
        !IsBlank(searchField.Text);
        Filter(
            myContracts;
            StartsWith(Nachname; searchField.Text) || StartsWith(Mitgliedsnummer;searchField.Text) 
        );
        Filter(
            myContracts;
            ArtName = DropdownGew.SelectedText.Value
        )
    );
    "Mitgliedsnummer";
    If(
        SortDescending1;
        Descending;
        Ascending
    )
)

Has anyone an idea for me?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Helper I
Helper I

Re: Avoid duplicate entries in a gallery

If you use Distinct() you can create a unique list of users names or IDs or what have you.  Use the resulting list to filter the result.  No guarantee of the order of the user of course.  Here's some code I created to solve my problem:

 

ClearCollect(
    _itemsAll,
    ProjectItems
);
ClearCollect(
    _currentList,
    Defaults(_itemsAll)
);
Clear(_currentList);
ForAll(
    Distinct(
        _itemsAll,
        Project.Id
    ),
    If(
        Count(
            Filter(
                _currentList,
                Project.Id = Result
            ).ID
        ) = 0,
        Collect(
            _currentList,
            First(
                Sort(
                    Filter(
                        _itemsAll,
                        Project.Id = Result
                    ),
                    'Report Date',
                    Descending
                )
            )
        )
    )
)

ProjectItems is my main list.  To explain:

 

  1. Create a collection (listAll) from the source list (this is a performance feature) 
  2. Create temp collection (_currentList) patterned after main list
  3. Clear the temp collection
  4. Iterate through each project (using Distinct)
  5. If the project ID is not found in the temp list
    • Get a list of all the specified project ID sorted by date
    • Add the first one to the temp list

Hope this helps.

v/r,

Bill

View solution in original post

1 REPLY 1
Highlighted
Helper I
Helper I

Re: Avoid duplicate entries in a gallery

If you use Distinct() you can create a unique list of users names or IDs or what have you.  Use the resulting list to filter the result.  No guarantee of the order of the user of course.  Here's some code I created to solve my problem:

 

ClearCollect(
    _itemsAll,
    ProjectItems
);
ClearCollect(
    _currentList,
    Defaults(_itemsAll)
);
Clear(_currentList);
ForAll(
    Distinct(
        _itemsAll,
        Project.Id
    ),
    If(
        Count(
            Filter(
                _currentList,
                Project.Id = Result
            ).ID
        ) = 0,
        Collect(
            _currentList,
            First(
                Sort(
                    Filter(
                        _itemsAll,
                        Project.Id = Result
                    ),
                    'Report Date',
                    Descending
                )
            )
        )
    )
)

ProjectItems is my main list.  To explain:

 

  1. Create a collection (listAll) from the source list (this is a performance feature) 
  2. Create temp collection (_currentList) patterned after main list
  3. Clear the temp collection
  4. Iterate through each project (using Distinct)
  5. If the project ID is not found in the temp list
    • Get a list of all the specified project ID sorted by date
    • Add the first one to the temp list

Hope this helps.

v/r,

Bill

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,863)