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
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

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,952)