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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sort table gallery by ...
Power Apps
Answered

Sort table gallery by related table column

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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
    Microsoft Employee on at

    Hi @AnthonyDo ,

     

    I noticed that the name of the lookup column in the image is ‘new_traineeyearlybudget’.

    vxiaochenmsft_0-1629077926238.png

     

    But the name of  lookup column in the formula is 'cref8_remainingbudget'.

    vxiaochenmsft_1-1629078008123.png

     

    Which one is your lookup column name?

     

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

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-xiaochen-msft ,

     

    The column "Remainingbudget" from table "TraineeYearlyBudget" is the column i am trying to add and sort on.

     

    Kind regards,


    Anthony

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @AnthonyDo ,

     

    What's the data type of "Remainingbudget"? Is it a text column or anything else?

     

    Best Regards,

    Wearsky

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-xiaochen-msft ,

     

    It is a decimal number column.

     

    Kind regards,


    Anthony

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    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.

     

     

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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
    Microsoft Employee on at

    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
    Microsoft Employee on at

    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

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @AnthonyDo ,

     

    This method is indeed better.

    You could use this in your gallery Items formula.

    I think it will work.

     

    Best Regards,

    Wearsky

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 103

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
wolenberg_ Profile Picture

wolenberg_ 67 Super User 2026 Season 1

Last 30 days Overall leaderboard