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 / Lookup Function only c...
Power Apps
Suggested Answer

Lookup Function only copying the first match for the entire table

(1) ShareShare
ReportReport
Posted on by 4
Dear All,

I'm trying to create a gallery table, where I want to add a column with the predicted hours, just like the vlookup on excel, having task name as my reference. However, it is only picking the first value of my prediction and copying the same for the entire table. My code and intermediate JSON results look like the following:
ClearCollect(
    PredictionResults,
    tasks_estimator.predicttask({
        base_item_code: Concat(FilteredDataTable, ProductCode & ":"),
        customer: customername,
        offering_category: ProjectTypeDropdown.Selected.Value,
        country: Dropdown_Country.Selected.Value,
        region: Dropdown_Region.Selected.Value
    })
);
ClearCollect(
    TaskCollection,
    ForAll(
        Sequence(CountRows(First(PredictionResults).'1_predicted_task_names')),
        {
            TaskName: Index(First(PredictionResults).'1_predicted_task_names', Value).Value,
            TotalPredictedHours: Index(First(PredictionResults).'2_predicted_task_hours', Value).Value
        }
    )
);

JSON(TaskCollection) - RESULTS of my prediction data coming from a machine learning model through a custom connector

[{"TaskName":"Other costs","TotalPredictedHours":94.398},{"TaskName":"Integration Work","TotalPredictedHours":54.921499999999995},{"TaskName":"Training","TotalPredictedHours":94.398},{"TaskName":"Engineering Work","TotalPredictedHours":78.1025},{"TaskName":"Project Management","TotalPredictedHours":41.467},{"TaskName":"Quality & other costs","TotalPredictedHours":19.779},{"TaskName":"Factory Inspection T","TotalPredictedHours":26.664},{"TaskName":"Installations & SAT","TotalPredictedHours":23.406000000000002}]

ClearCollect(
    MergedTaskSummaries,
    ForAll(
        TaskSummaries,
       {TaskName: ThisRecord.TaskName,
        TotalQuantity: ThisRecord.TotalQuantity,
        TotalPredictedHours: If(
            IsBlank(LookUp(TaskCollection, TaskName = ThisRecord.TaskName, TotalPredictedHours)),
             "N/A",
             LookUp(TaskCollection, TaskName = ThisRecord.TaskName, TotalPredictedHours)
            )
        }
    )
);

JSON(MergedTaskSummaries) - FINAL RESULT OF MY GALLERY

[{"TaskName":"Project Management","TotalPredictedHours":"94.398","TotalQuantity":4},{"TaskName":"Integration Work","TotalPredictedHours":"94.398","TotalQuantity":2},{"TaskName":"Installations & SAT","TotalPredictedHours":"94.398","TotalQuantity":7},{"TaskName":"Engineering Work","TotalPredictedHours":"94.398","TotalQuantity":2},{"TaskName":"Factory Inspection T","TotalPredictedHours":"94.398","TotalQuantity":1},{"TaskName":"Other costs","TotalPredictedHours":"94.398","TotalQuantity":null},{"TaskName":"Quality","TotalPredictedHours":"94.398","TotalQuantity":null},{"TaskName":"Training","TotalPredictedHours":"94.398","TotalQuantity":2},{"TaskName":"Factory Acceptance T","TotalPredictedHours":"94.398","TotalQuantity":null},{"TaskName":"Site Survey","TotalPredictedHours":"94.398","TotalQuantity":null}]

 

What's the best way to merge the results of my taskcollection table with the already present task summaries table?

Thanks!
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,960 Moderator on at
    Hi 
     
    I do not see any code or images.

    Unfortunately, if I reload a zillion times, i see your code snippet(thank you) for only a moment and then its gone.

    However, you say you are using a LookUp, but lookups only return 1 row, never more.

    Ugg wish I could see your code
  • Suggested answer
    MichaelFP Profile Picture
    1,943 Moderator on at
    Hello! You are not using the Lookup to get the specific record, using First() you will always get the first item of the collection it will be the same. You must use Lookup function to find the specific record.
     

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
WarrenBelz Profile Picture

WarrenBelz 493 Most Valuable Professional

#2
11manish Profile Picture

11manish 479

#3
Haque Profile Picture

Haque 328

Last 30 days Overall leaderboard