Power Apps Exchange

Please login or click SIGN UP FOR FREE to create your PowerAppsUG account to join this user group.
 View Only
Expand all | Collapse all

SortByColumns not working with GroupBy and AddColumns.

Jump to Best Answer
  • 1.  SortByColumns not working with GroupBy and AddColumns.

    Posted Sep 29, 2021 09:47 AM

    Hello,

    I have a wellness app that counts a users steps on two screens, one screen tracks personal steps while the other tracks their team steps. The personal saves every entry into a gallery but I would like the team gallery to group each team members steps into one item as a total. I get this working to some degree when I add the following to the gallery's items property:

    (GroupBy(Filter([@'Wellness Challenge'], TeamName.Value=vMyTeam.Value),"TeamNamePipe","NamePipe","Steps"))

    Then when I insert the AddColumns (To sum the overall steps) and the SortByColumns it does not work.

    SortByColumns(GroupBy(AddColumns(Filter([@'Wellness Challenge'],TeamName.Value=vMyTeam.Value),"StepsColumn",Steps),"StepsColumn","TeamNamePipe","NamePipe","Steps"),"StepsColumn",If(SortDescending1, Descending, Ascending))

    The AddColumns throws an error when I add the following to the label text property:

    Sum(ThisItem.StepsColumn,ThisItem.StepsColumn)

    The steps column in my SP list is a Number field and the AddColumn is named StepsColumn. Is there an issue in the order of the functions?

    Thank you



    ------------------------------
    Fernand B
    Senior Application Developer
    ------------------------------


  • 2.  RE: SortByColumns not working with GroupBy and AddColumns.
    Best Answer

    Posted Sep 29, 2021 09:46 PM

    Got help from my colleague and got it working. Created a collection on the OnVisible of the screen:

    UpdateContext({SortDescending1: true});
    ClearCollect(
    colWellness,
    DropColumns(
    AddColumns(
    GroupBy(
    Filter(
    'Wellness Challenge',
    TeamName.Value = vMyTeam.Value
    ),
    "TeamNamePipe",
    "NamePipe",
    "GroupedTeams"
    ),
    "Sum of Steps",
    Sum(
    GroupedTeams,
    Steps
    )
    ),
    "GroupedTeams"
    )
    );


    Then added the following to the label for a sum:

    SortByColumns(colWellness,"Sum of Steps",If(SortDescending1, Descending, Ascending))



    ------------------------------
    Fernand B
    Senior Application Developer
    ------------------------------