cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tamer66 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
TiredOldCoder 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
TiredOldCoder 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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

Top Solution Authors
Top Kudoed Authors
Users online (8,786)