How to get distinct Gallery tiles in PowerApps?

五迷三道 提交于 2021-01-29 07:09:40

问题


My DataSource for PowerApps is Excel Table. After user's Entry, the excel Table looks like below. In below image one can see that "Sys1" appears twice in Excel Table, leading to creating one extra tile for same system Gallery in PowerApps.My Question is How to avoid duplication of tile creation in PowerApps ? Below is code for Gallery and Tile. I am new to PowerApps. Provide code with explanation .

Note: I forgot to add Name after Sys. The 1st column name in below screenshot should be "Sys Name"

Gallery ->Items Property [CODE]

Filter(Table1,Startswith('Sys Name'),"Sys"))

Tile -> Text Property [CODE]

ThisItem.'Sys Name'

回答1:


To remove duplicates you can use the GroupBy function and take the First of the elements in each group. Once you have that, you can use some of the table shaping functions (AddColumns, DropColumns) to recreate the original column structure, if necessary:

DropColumns(
    AddColumns(
        GroupBy(
            Filter(Table1, StartsWith('Sys',"Sys")),
            "Sys",
            "BySys"),
        "Model#", First(BySys).'Model#',
        "Current Status", First(BySys).'Current Status',
        "Previous Status", First(BySys).'Previous Status'),
    "BySys")

The way you can read the expression above is from inside out: first filter the Table1 only for those rows whose 'Sys' column starts with "Sys" (what you had originally). The result of the filter will be grouped by the 'Sys' column, with all rows that have similar values grouped in the 'BySys' column. To this result, we add three columns: 'Model#', 'Current Status' and 'Previous Status', by taking the first of the grouped elements. Finally we remove the grouped column ('BySys') at the outermost function.

If you don't want to have to list all of the properties of the original data source in the expression, you can stay with the GroupBy expression as the Items of your gallery:

GroupBy(
    Filter(Table1, StartsWith('Sys',"Sys")),
    "Sys",
    "BySys")

In the gallery template, you can have a label that shows the 'Sys' column directly as ThisItem.Sys, but if you want to access the other columns, you will need to choose, from the group, what you want to display. For example, to display the model number of the first row for that specific 'Sys' value, you can have this expression as the Text property of a label:

First(ThisItem.BySys).'Model#'

Yet another option, if you want to show many other properties and don't want to keep repeating the call to First is to add that as another (record) property of the gallery items:

AddColumns(
    GroupBy(
        Filter(Table1, StartsWith('Sys',"Sys")),
        "Sys",
        "BySys"),
    "FirstSys", First(BySys))

And now in your gallery you can have labels with the following properties:

ThisItem.FirstSys.'Model#'
ThisItem.FirstSys.'Current Status'

And so on.



来源:https://stackoverflow.com/questions/64580098/how-to-get-distinct-gallery-tiles-in-powerapps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!