cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tamer66
Level: Powered On

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
TiredOldCoder
Level: Powered On

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
TiredOldCoder
Level: Powered On

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,553)