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 / How to show results us...
Power Apps
Unanswered

How to show results using data source and collection in one gallery

(0) ShareShare
ReportReport
Posted on by 327

Hi all 

 

I would like to get the nearest clinic for each record by using SP list

results will be coming from a collection 

how would I combine data source + collection to display results in one gallery 

 

My collection code:

ClearCollect(ClnicRoute2, {Name:"Wapping & Bigland Children’s Centre", Address:"E1 2JP"});
Collect(ClnicRoute2, {Name:"T1", Address:"RAN1 0ND"});
Collect(ClnicRoute2, {Name:"T2", Address:"RAN1 2EN"});
Collect(ClnicRoute2, {Name:"T3", Address:"RAN1 0AF"});
Collect(ClnicRoute2, {Name:"T4", Address:"RAN1 3BX"});
Collect(ClnicRoute2, {Name:"T5", Address:"RAN1 6AW"});
Collect(ClnicRoute2, {Name:"T6", Address:"RAN1 8AP"});
Collect(ClnicRoute2, {Name:"T7", Address:"RAN1 0NU"});
Collect(ClnicRoute2, {Name:"T8", Address:"RAN1 9DL"});
Collect(ClnicRoute2, {Name:"T9", Address:"RAN1 8JH"});
Collect(ClnicRoute2, {Name:"T10", Address:"RAN1 3LL"});
Collect(ClnicRoute2, {Name:"T11", Address:"RAN1 5DS"});
Collect(ClnicRoute2, {Name:"T12", Address:"RAN1 2RU"});
Collect(ClnicRoute2, {Name:"T13", Address:"RAN1 0SN"});
Collect(ClnicRoute2, {Name:"T14", Address:"RAN1 4GY"});
Collect(ClnicRoute2, {Name:"T15", Address:"RAN1 5QT"});
Collect(ClnicRoute2, {Name:"T16", Address:"RAN1 8HQ"});

ClearCollect(
 ClnicDistance2,
 AddColumns(
 ClnicRoute2,
 "DistanceToClnic",
 BingMaps.GetRouteV3("Walking", ThisItem.Postcode2, Address, {distanceUnit:"Mile"}).travelDistance
 )
);

// Sort the collection by "DistanceToClnic" in ascending order
ClearCollect(SortedClnicDistance, SortByColumns(ClnicDistance, "DistanceToClnic", Ascending));

// Get the clinic with the shortest distance
ClearCollect(ShortestDistanceClinic, First(SortedClnicDistance));

Gallery: 

moerah_1-1703117095479.png

 

I hope I made sense 

Thank you all

Categories:
I have the same question (0)
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @moerah ,

     

    Could you please share more details? Can below formula work?

    ClearCollect(
     ClnicDistance2,
     AddColumns(
     ClnicRoute2,
     "DistanceToClnic",
     BingMaps.GetRouteV3("Walking", ThisItem.Postcode2, Address, {distanceUnit:"Mile"}).travelDistance
     )
    );


    I cannot see Postcode2 column from the collection ClnicDistance2, where did it come from?

     

    Best regareds

  • moerah Profile Picture
    327 on at

    Thank you for the reply

     

    i have nested gallery postcode2 is coming from gallery 1

    moerah_0-1703127515929.png

    test button has the collection code

    nearest clinic is gallery 2  

    I would like to have one button to calculate the miles for all records instead of clicking each button to get the result.

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @moerah ,

     

    So, you have a Gallery connects to a SP list where includes a Postcode column. In this case, you can apply below codes OnVisible of current screen:

    ClearCollect(
     ClnicRoute2,
     {Name:"Wapping & Bigland Children’s Centre", Address:"E1 2JP"},
     {Name:"T1", Address:"RAN1 0ND"},
     {Name:"T2", Address:"RAN1 2EN"},
     {Name:"T3", Address:"RAN1 0AF"},
     {Name:"T4", Address:"RAN1 3BX"},
     {Name:"T5", Address:"RAN1 6AW"},
     {Name:"T6", Address:"RAN1 8AP"},
     {Name:"T7", Address:"RAN1 0NU"},
     {Name:"T8", Address:"RAN1 9DL"},
     {Name:"T9", Address:"RAN1 8JH"},
     {Name:"T10", Address:"RAN1 3LL"},
     {Name:"T11", Address:"RAN1 5DS"},
     {Name:"T12", Address:"RAN1 2RU"},
     {Name:"T13", Address:"RAN1 0SN"},
     {Name:"T14", Address:"RAN1 4GY"},
     {Name:"T15", Address:"RAN1 5QT"},
     {Name:"T16", Address:"RAN1 8HQ"}
    );

    Then Gallery Items would be:

    AddColumns(
     'CSV file to SP PostCode' As PC,
     "Nearest clinic",
     First(
     SortByColumns(
     AddColumns(
     ClnicRoute2 As CR,
     "DistanceToClnic",
     BingMaps.GetRouteV3("Walking", PC.Postcode2, CR.Address,{distanceUnit:"Mile"}).travelDistance
     ),
     "DistanceToClnic", Ascending
     )
     ).DistanceToClnic
    );

     

    Label in the Gallery to display the distance:

    ThisItem.'Nearest clinic'

     

    Best regards,

  • moerah Profile Picture
    327 on at

    thanks for the reply

     

    it's giving me some sort of error for "SortByColumns"

    moerah_0-1703152717204.png

     

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @moerah ,

     

    I missed something for the SortByColumns function.

    AddColumns(
     'CSV file to SP PostCode' As PC,
     "Nearest clinic",
     First(
     SortByColumns(
     AddColumns(
     ClnicRoute2 As CR,
     "DistanceToClnic",
     BingMaps.GetRouteV3("Walking", PC.Postcode2, CR.Address,{distanceUnit:"Mile"}).travelDistance
     ),
     "DistanceToClnic", SortOrder.Ascending
     )
     ).DistanceToClnic
    );

     

    Best regards,

  • moerah Profile Picture
    327 on at

    Thank you for the reply

     

    everything is working but now I'm getting "This formula uses scope, which is not presently supported for evaluation. Data type: number"  when i insert the text label (thisitem.Nearest clinic) in the gallery.

    moerah_0-1703161465909.png

     

     

     

     

     

  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @moerah ,

     

    It's just a warning, indicating that you cannot see the result of the formula because it uses a scope. As long as it can display values in Gallery, it's working fine.

     

    Best regards,

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard