web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : YNtDF11ZrsgT84qImHQF/w
Power Apps - Microsoft Dataverse
Answered

Sort table gallery by related table column

Like (0) ShareShare
ReportReport
Posted on 15 Aug 2021 16:08:43 by

Hello everyone,

 

I would like to sort a gallery with sourcetable Trainees by a column from a related table. That column is "cref8_remainingbudget" from the table TraineeYearlyBudget. 

 

I made a lookup field in my Trainees table. You can see this in the picture underneath.

 

AnthonyDo_0-1629043383002.png

 

 

So i tried to do this myself but i can't get it to work. The code underneath is what i currently have (and is not working).

 

!IsBlank(varSortByBudget),
 SortByColumns(
 AddColumns(
 Trainees,
 "cref8_remainingbudget",
 traineeyearlybudget.cref8_remainingbudget

 ),
 "cref8_remainingbudget",
 If(
 varSortByBudget,
 Ascending,
 Descending
 )
 )

 

 

 

What am i doing wrong here?

 

thanks in advance,

 

Anthony

I have the same question (0)
  • v-xiaochen-msft Profile Picture
    on 17 Aug 2021 at 01:19:24
    Re: Sort table gallery by related table column

    Hi @AnthonyDo ,

     

    What if you only use this formula in items? Will it report an error?

    SortByColumns(
     AddColumns(
     Trainees As A,"cref8_remainingbudget",LookUp(TraineeYearlyBudgets,TraineeYearlyBudgets=A.traineeyearlybudget.TraineeYearlyBudgets).Remainingbudget),
     
     Ascending
     )

     

    And I see an obvious error in your formula.

    The addcolumns() function is missing one ')'.

    vxiaochenmsft_0-1629163157262.png

     

     

    Best Regards,

    Wearsky

     

  • Community Power Platform Member Profile Picture
    on 16 Aug 2021 at 10:02:39
    Re: Sort table gallery by related table column

    hi @v-xiaochen-msft , 

     

    that did not work either 😕 

     

    code: 

     

     SortByColumns(
     AddColumns(
     Trainees As A,"cref8_remainingbudget",LookUp(TraineeYearlyBudgets,TraineeYearlyBudgets=A.traineeyearlybudget.TraineeYearlyBudgets).Remainingbudget,
     If(
     varSortByBudget,
     Ascending,
     Descending
     )
     )

     

     

    screen of error:

     

    2021-08-16 12_03_27-Power Apps.png

     

     

     

    Kind regards,

     

    Anthony

  • Verified answer
    v-xiaochen-msft Profile Picture
    on 16 Aug 2021 at 07:23:22
    Re: Sort table gallery by related table column

    Hi @AnthonyDo ,

     

    Please try this:

    AddColumns(Trainees As A,"cref8_remainingbudget",LookUp(TraineeYearlyBudget,TraineeYearlyBudget=A.traineeyearlybudget.TraineeYearlyBudget).Remainingbudget)

     // TraineeYearlyBudget is a guid column.

    // traineeyearlybudget is a lookup column .

     

    Best Regards,

    Wearsky

  • Community Power Platform Member Profile Picture
    on 16 Aug 2021 at 07:05:20
    Re: Sort table gallery by related table column

    How would i implement this inside the gallery items formula. However i try to implement this is keeps throwing me errors. 

     

    2021-08-16 09_04_09-Power Apps.png

  • v-xiaochen-msft Profile Picture
    on 16 Aug 2021 at 06:57:54
    Re: Sort table gallery by related table column

    Hi @AnthonyDo ,

     

    This method is indeed better.

    You could use this in your gallery Items formula.

    I think it will work.

     

    Best Regards,

    Wearsky

  • Community Power Platform Member Profile Picture
    on 16 Aug 2021 at 06:55:56
    Re: Sort table gallery by related table column

    i have another label in the gallery and this does show me the remainingbudget for each trainee:

     

    2021-08-16 08_54_38-Power Apps.png

  • Community Power Platform Member Profile Picture
    on 16 Aug 2021 at 06:46:17
    Re: Sort table gallery by related table column

    Dear @v-xiaochen-msft 

     

    My full gallery code:

     

    If(
     !varShowOutOfServiceEmployees,
     If(
     !IsBlank(varSortByName),
     SortByColumns(
     Filter(
     Trainees,
     cref8_outofservice <> 'Out Of Service (Trainees)'.'1' || cref8_outofservice = 'Out Of Service (Trainees)'.'1' && cref8_employmentenddate > Today()
     ),
     "cref8_firstname",
     If(
     varSortByName,
     Ascending,
     Descending
     ),
     "cref8_lastname",
     If(
     varSortByName,
     Ascending,
     Descending
     )
     ),
     !IsBlank(varSortByBudget),
     SortByColumns(
     Filter(
     Trainees,
     cref8_outofservice <> 'Out Of Service (Trainees)'.'1' || cref8_outofservice = 'Out Of Service (Trainees)'.'1' && cref8_employmentenddate > Today()
     ),
     "cref8_trainingbudget",
     If(
     varSortByBudget,
     Ascending,
     Descending
     )
     ),
     !IsBlank(varSortByTrainingDays),
     SortByColumns(
     Filter(
     Trainees,
     cref8_outofservice <> 'Out Of Service (Trainees)'.'1' || cref8_outofservice = 'Out Of Service (Trainees)'.'1' && cref8_employmentenddate > Today()
     ),
     "cref8_trainingdays",
     If(
     varSortByTrainingDays,
     Ascending,
     Descending
     )
     ),
     Trainees
     ),
     If(
     !IsBlank(varSortByName),
     SortByColumns(
     Trainees,
     "cref8_firstname",
     If(
     varSortByName,
     Ascending,
     Descending
     ),
     "cref8_lastname",
     If(
     varSortByName,
     Ascending,
     Descending
     )
     ),
     !IsBlank(varSortByBudget),
     SortByColumns(
     AddColumns(
     Trainees,
     "cref8_remainingbudget",
     ThisRecord.traineeyearlybudget.'Remaining Budget'
     ),
     "cref8_remainingbudget",
     If(
     varSortByBudget,
     Ascending,
     Descending
     )
     ),
     !IsBlank(varSortByTrainingDays),
     SortByColumns(
     AddColumns(
     Trainees,
     "cref8_remainingdays",
     ThisRecord.traineeyearlybudget.'Remaining Days'
     ),
     "cref8_remainingdays",
     If(
     varSortByTrainingDays,
     Ascending,
     Descending
     )
     ),
     Trainees
     )
    )

     

    My label inside gallery:

     

    2021-08-16 08_44_10-Power Apps.png

     

    The gallery code is not giving any errors.

     

    King Regards,

    Anthony

     

     

  • v-xiaochen-msft Profile Picture
    on 16 Aug 2021 at 06:40:59
    Re: Sort table gallery by related table column

    Hi @AnthonyDo ,

     

    Could you share some screenshots?

    For example : your gallery's Items formula & your label formula ...

     

    And does the formula report an error?

     

    Best Regards,

    Wearsky

  • Community Power Platform Member Profile Picture
    on 16 Aug 2021 at 06:37:11
    Re: Sort table gallery by related table column

    Dear @v-xiaochen-msft ,

     

    I tried your code and for me it is not working. I added a label to my gallery with text property: 

    ThisItem.traineeyearlybudget.'Remaining Budget'. It doesn't show me any values though. I think something is not right with my lookup?
     
    Kind regards,
    Anthony
  • v-xiaochen-msft Profile Picture
    on 16 Aug 2021 at 06:20:23
    Re: Sort table gallery by related table column

    Hi @AnthonyDo ,

     

    I did a demo for you.

    1\ Table 'TraineeYearlyBudget'

    vxiaochenmsft_0-1629094331919.png

     

    2\ Table 'Trainees'

    vxiaochenmsft_1-1629094349256.png

     

    3\ Their relationship

    vxiaochenmsft_2-1629094372645.png

     

    4\ Add a gallery control and set its Items property to:

    SortByColumns(AddColumns(Trainees,"cref8_remainingbudget",ThisRecord.traineeyearlybudget.Remainingbudget),"cref8_remainingbudget",Ascending)

     

    5\ The result is as follows:

    vxiaochenmsft_3-1629094814661.png

     

    Best Regards,
    Wearsky
    If my post helps, then please consider Accept it as the solution to help others. Thanks.

     

     

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Featured topics

Loading complete