Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Answered

Sort table gallery by related table column

(0) ShareShare
ReportReport
Posted on 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

  • v-xiaochen-msft Profile Picture
    on at
    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 at
    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 at
    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 at
    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 at
    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 at
    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 at
    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 at
    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 at
    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 at
    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
stampcoin Profile Picture

stampcoin 17

#2
mmbr1606 Profile Picture

mmbr1606 15 Super User 2025 Season 1

#3
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

Overall leaderboard

Featured topics