cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AoLMatthieu
Frequent Visitor

Excel matching issue using PowerAutomateWeb

Hi guys, hope you are doing good,

 

Having the following issue:

 

I have ExcelFile1 with some weekly data in Table1

I have ExcelFile2 with some daily data in Table2

 

Both excel are differents, not the same document

 

I am trying to match and retrieve the lines where Column A of both is similar. Retrieve full info of these lines from ExcelFile1 and add to it one column from ExcelFile2

 

AoLMatthieu_0-1688476472351.png

 

Here is current flow:

 

-Foreach: it opens value of list lines in table1

-Foreach: it opens value of list lines in table2

-Compare when colum A from each document is similar

-Add the infos into a table variable

-Then I create a new document with a new table that have the data from there

 

 

Any Idea how to make it work ? Am I approaching it wrongly ?

 

Thanks,

9 REPLIES 9
rzaneti
Super User
Super User

Hi @AoLMatthieu ,

 

Based on your description, this is a possible approach to achieve your goal. However, it is not clear where exactly you are finding the error. 

 

To identify the source of the error, I ask you the following:

  • Do you know which action is causing the error to your flow? If yes, please share the raw outputs from the action. If not, please share the raw inputs from your 'Ajouter a la variable de tableau', and confirm if the 'TableauFinal' variable is for data type 'Array'.
  • Do you currently have any other actions after your loops? If yes, please 

 

To access the raw inputs/outputs, you just need to go to the flow run page, navigate until the specific action and click in these buttons:

rzaneti_0-1688504541596.png

 

 

 

It will open a JSON view in a sidebar or in a new tab:

rzaneti_1-1688504541713.png

 

 

Find the "body" property (you can search it with Ctrl+F). Make sure to remove any sensitive content from the image before sharing it here 

 

If you still have any trouble to find the raw inputs/outputs, let me know and I guide you! Also, this article provides additional details about how does these raw inputs/outputs work and how to access them: http://digitalmill.net/2023/06/29/how-to-access-the-raw-outputs-in-power-automate/

Hey @rzaneti 

 

Thanks a lot for your answer,

 

The flow basically timesout while trying to get inside the first for each (which also seems limited to 256 entrance(my file has more lines than that)

 

AoLMatthieu_0-1688546351498.png

I can't really see where it struggles because of that

 

Thanks,

Hi @AoLMatthieu ,

 

Thank you for the image. Apparently you are receiving a 'timeout' when looping your tables. 

 

As a first idea to try to solve the problem, try to change the concurrency control from your loops. You can find this option in the "settings" from your 'Apply to each' action (it will make your loop iterations run in a non sequential way):

rzaneti_0-1688557677346.png

rzaneti_1-1688557773935.png

 

 

You will find more details about how to do it in the accepted answer from this post: https://powerusers.microsoft.com/t5/Building-Flows/Apply-to-each-Timeout/td-p/539959 .

 

I also found this community post about it (https://powerusers.microsoft.com/t5/General-Power-Automate/Flow-timeout-on-apply-to-each/td-p/207403... ), and the conclusion is basically that you have some limits for the 'apply to each' action depending on your Power Automate license. I know that one of your tables has 247 records; how many records has the other one?

Hey @rzaneti 

Thanks for your answer, i did the settings change but seems like it still doesnt work for the same issue

 

My documents do have 922 and 208 lines. Do you think there would be an other way to achieve what I am trying to do ?

 

Many thanks,

Hi @AoLMatthieu ,

 

A possible solution is the 'Office Scripts'. The Office Scripts are a JavaScript library that allows you to manipulate Excel and read/write data on it. It is similar to VBA, but for Excel Web. 

 

We can try to build a Script to add this extra column to your Excelfile1 to Excelfile2. To achieve it, please share a small sample with fake data from your table in Excelfile1 and your table in Excelfile2. This samples can have ~3 rows each... is just to understand the used data types and run the tests with a scenario close to the reality (in my environment, I will generate more rows in the same format from your sample, to achieve the approximated size of your tables).

AoLMatthieu
Frequent Visitor

Hey @rzaneti 

 

Sorry for late answer, summer period :s 

 

I tried to create the following script but it aint working : 

 

Excel.run(function (context) {
  //open files
  var file1 = context.workbook.application.workbooks.open("pathfile1.xlsx");
  var file2 = context.workbook.application.workbooks.open("pathfile2.xlsx");

  // get worksheet of files
  var sheet1 = file1.worksheets.getActiveWorksheet();
  var sheet2 = file2.worksheets.getActiveWorksheet();

  // column range i want to compare between both documents
  var range1 = sheet1.getRange("H:H");
  var range2 = sheet2.getRange("H:H");

  // load data
  range1.load("values");
  range2.load("values");

  return context.sync().then(function () {
    // comparison
    var data1 = range1.values;
    for (var i = 0; i < data1.length; i++) {
      var value = data1[i][0];

      // check if it exists
      if (value !== "") {
        var existsInFile2 = false;
        var data2 = range2.values;
        for (var j = 0; j < data2.length; j++) {
          if (data2[j][0] === value) {
            existsInFile2 = true;
            break;
          }
        }

        // if exists, copy and paste into do3
        if (existsInFile2) {
          var rowToCopy = sheet1.getRange("A" + (i + 1) + ":Z" + (i + 1));
          var destinationRange = file1.worksheets.getItem("Sheet1").getRange("A1");

          // 
          rowToCopy.copyTo(destinationRange);

          // path3
          var file3Path = "pathfile3.xlsx";

          // save file3
          return file1.saveCopyAs(file3Path).then(function (file3) {
            // add infos of additional column
            var sheet3 = file3.worksheets.getActiveWorksheet();
            var range2B = sheet2.getRange("L:L");
            range2B.load("values");

            return context.sync().then(function () {
             
              var data2B = range2B.values;
              var columnBValues = [];
              for (var k = 0; k < data2B.length; k++) {
                columnBValues.push([data2B[k][0]]);
              }

              // add the new column at the end of the document of file3
              var usedRange3 = sheet3.getUsedRange();
              var lastColumn = usedRange3.getLastColumn();
              var destinationRangeB = usedRange3.getCell(1, lastColumn + 1);
              destinationRangeB.values = columnBValues;

              // save
              return file3.save();
            });
          });
        }
      }
    }

    // Close
    file1.close();
    file2.close();

    return context.sync();
  }).catch(function (error) {
    console.log(error);
  });
});

Having errors : 

See line 3, column 7: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 4, column 7: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 7, column 7: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 8, column 7: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 11, column 7: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 12, column 7: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 20, column 9: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 22, column 11: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 27, column 13: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 37, column 15: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 38, column 15: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 49, column 17: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 50, column 17: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 55, column 19: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 62, column 19: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 63, column 19: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 64, column 19: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

See line 56, column 19: Office Scripts cannot infer the data type of this variable. Please declare a type for the variable.

 

 

Document look like this (attached). Document2 would look like the same with some ID in common, not all, rest of the data would also be the same, only spend column would be different

 

I take then the common lines (I use column campaign ID to compare) and put them in document 3, I add a new column to the document which is = to the column spend from document 2 (and of course it goes on the line with the correct ID)


Hope that's this is clear... if not let me know

 

Thanks a lot !

Hi @AoLMatthieu ,

 

I'm not sure if your approach with Office Scripts will be suitable to run integrated with Power Automate. Are you storing and running this script in the Excel Code Editor?

 

Some days ago (after your post), I answered another post here in the community with a partially similar problem: the user needed to collect data from an Excel file and use it in another. This is not the exact same problem as yours, but you can leverage the steps that we took there to extract data from your 2 files and insert it into the final file. 

 

This is the post: https://powerusers.microsoft.com/t5/Building-Flows/Compare-2-excel-and-highlight-the-row-with-differ...

 

Let me know if it works for you. I believe that you can use part or the code that you sent above in this new approach. 

AoLMatthieu
Frequent Visitor

Hi @rzaneti 

I run the script from power automate and I store it in the excel code editor, this has been working for other scripts I have done, why shouldn't it there ?

 

Going to check it out !

Thanks,

Hi @AoLMatthieu ,

 

Your method is correct: you can call a script written in the Excel Code Editor from Power Automate. But the Script has some limitations, and it needs to have a main function, for example. I saw that you are using an Excel.Run method - which is used in the Office Add Ins -, but for manipulating the Scripts inside Excel Web and call them via Power Automate, you technically cannot use it. 

 

In summary, the logic of your code seems to be perfectly correct, but some small changes will be needed to fit it to the Office Scripts.

 

I'm sharing with you two articles about the basic use of the Office Scripts and its difference from the 'Add-Ins':

https://learn.microsoft.com/en-us/office/dev/scripts/resources/add-ins-differences

https://learn.microsoft.com/en-us/office/dev/scripts/develop/scripting-fundamentals

http://digitalmill.net/2023/06/19/get-started-with-office-scripts/

 

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (955)