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

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

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 56 members 4,393 guests
Please welcome our newest community members: