Skip to main content

Notifications

Power Platform Community / Forums / Building Flows / Need help using Excel ...
Building Flows
Suggested answer

Need help using Excel formulae in "Add a row" flow

Posted on by 6
 
I'm working on a somewhat complicated but ultimately straightforward business process that:
 
1. Takes user input from MS Forms and writes that data to an Excel workbook stored on SharePoint, using a Power Automate Flow
2. Runs calculations on the submitted data to populate specific cells in a specific worksheet within the destination workbook (still using Power Automate)
 
I have created a Flow in Power Automate to organize how the data is written to the workbook using the "Add a Row" function. The Flow works -- I have tested it dozens of times, including completing the form many times to test the whole process. However, where I am consistently stuck is in getting my Excel formulae to function consistently and accurately.
 
The formulae are, in some cases, very basic and in others much more complex, but they work. The problem is, I can't get them to work for each new row that Power Automate writes into the workbook.
 
For example, two of the questions in the form ask for a number to be input into a text field by the user. When the numbers are written into the spreadsheet, I run a simple calculation on each figure that divides it by a standard value to arrive at a percentage. This calculation works, but ONLY on the first row. All subsequent rows added to the spreadsheet continue calculating based on the values entered the first time in the first row (in this case, Row 2).
 
In other words, if the first row of my table is Row 2 (because Row 1 contains headers, the formula looks like this:
 
=IF($F2=0,0,($F2/29.06))
 
If more data is submitted from the form, and I go to, say, Row 4, the formula is exactly the same -- it has not updated $F2 to $F4, so it is still calculating the values in Row 2, e.g., $F2. Here is a partial illustration of how the formulae are embedded in the Flow:
 
 
The second type of formula issue is slightly more complicated. For this one, I created a step in the Flow that adds a row to a worksheet table "Index." For "Index," I want to capture one piece of data entered into the form -- the value for "Country" -- and then run calculations on the rows of data received for that submission. (The Flow writes the form data to several different tables in different worksheets.) These calculations run at the end of the Flow, and are intended to analyze the most recent row in the table and calculate values based on the answer provided using VLOOKUP.
 
Here is an example of one of these:
 
=((VLOOKUP(AccessEquity!$B2,TelcoProviderValues,2,FALSE)
+IFNA(VLOOKUP(AccessEquity!$C2,WBAScoringValues,2,FALSE),0)
+VLOOKUP(AccessEquity!$D2,PercentageValuesLowHigh,2,FALSE)
+VLOOKUP(AccessEquity!$E2,PercentageValuesLowHigh,2,FALSE)
+IF(AND(AccessEquity!$G2>=0,$G2<=25.99),1,IF(AND($G2>=26,$G2<=50.99),2,IF(AND($G2>=51,$G2<=75.99),3,IF(AND($G2>=76,$G2<=100),4))))
+IF(AND(AccessEquity!$I2>=0,$I2<=25.99),1,IF(AND($I2>=26,$I2<=50.99),2,IF(AND($I2>=51,$I2<=75.99),3,IF(AND($I2>=76,$I2<=100),4))))
+IF(AND(AccessEquity!$K2>=0,$K2<=25.99),1,IF(AND($K2>=26,$K2<=50.99),2,IF(AND($K2>=51,$K2<=75.99),3,IF(AND($K2>=76,$K2<=100),4))))
+IF(AND(AccessEquity!$L2>=0,$L2<=25.99),1,IF(AND($L2>=26,$L2<=50.99),2,IF(AND($L2>=51,$L2<=75.99),3,IF(AND($L2>=76,$L2<=100),4))))
+IF(AND(AccessEquity!$M2>=0,$M2<=25.99),1,IF(AND($M2>=26,$M2<=50.99),2,IF(AND($M2>=51,$M2<=75.99),3,IF(AND($M2>=76,$M2<=100),4))))
+VLOOKUP(AccessEquity!$J2,PercentageValuesLowHigh,2,FALSE)
+VLOOKUP(AccessEquity!$N2,PercentageValuesLowHigh,2,FALSE)
+VLOOKUP(AccessEquity!$O2,PercentageValuesLowHigh,2,FALSE)
+VLOOKUP(AccessEquity!$P2,PercentageValuesLowHigh,2,FALSE)
+VLOOKUP(AccessEquity!$Q2,EquityValues,2,FALSE)
+VLOOKUP(AccessEquity!$T2,ReliabilityValues,2,FALSE)
+VLOOKUP(AccessEquity!$V2,AffordabilityValues,2,FALSE))/60)*4
 
As you can see, I'm using VLOOKUP to take the given response in the specified cells in a sheet named "AccessEquity", and then apply a numeric value to them based on value tables stored elsewhere in the workbook. These values are combined with IF statements to calculate values based on ranges for some responses, and then applying a score to them. Finally, I add them all together, divide by 60 and multiply that value by 4. The answers should be anywhere from 1 to 4, out to two decimal places.
 
I have embedded this formula (and the others) in the "Add a Row" functions in the Flow. Here is a partial illustration:
 
 
This calculation works successfully on the FIRST ROW (in this case, Row 2), and displays the calculated value in the appropriate cell. However, subsequent data submissions fail because the row number in the formula doesn't update. If I submit a second set of data, the formula in the first row (Row 2), changes to $B1 for some reason, and the newest submission (Row 3) becomes, e.g., $B2. Subsequent submissions also are, e.g., $B2, and do not increment to, e.g., $B3, $B4, $B5, etc., as in the previous example.
 
I have tried embedding the formulae in the "Add a Row" function in the Flow, as above, and it works, but only the first time.
 
Embedding the formulae in the destination workbook itself doesn't work because we are adding a row. I have tried using "Update a Row" for the final step, where the formula is embedded in the worksheet and I'm only updating the row to add the value for "Country" but that failed -- the Flow didn't work at all -- so if that is the correct approach I'm doing something wrong with "Update a Row" but I have no idea what.
 
So, is my approach completely wrong for what I am trying to do? Or am I making some kind of elementary mistake? Or neither?
  • Robby_WW Profile Picture
    Robby_WW 113 on at
    Need help using Excel formulae in "Add a row" flow
    @MB-26072021-0 can you define/predict the constant or load it from another source? which in turn you can make into a variable to put into that formula.
  • bisted1 Profile Picture
    bisted1 9 on at
    Need help using Excel formulae in "Add a row" flow
    It's probably not the optimal approach, and I suspect there is probably another way to write this formula but am unsure without seeing the underlying dataset, but have you tried Initializing a Variable at value 2, inserting the output into every use of the row instead of the number, and on each loop increment it by 1? i.e. on the first loop it will be $B2, then $B3, $B4 etc.
  • Robby_WW Profile Picture
    Robby_WW 113 on at
    Need help using Excel formulae in "Add a row" flow
    Hey,
     
    Are you not making this to complicated then it needs to be?
    Are these calculation numbers coming from your form questions?
     
    If yes then, use a compose or variable action with your calculations in it and use that output in your add row action.
    for example.
    if(equals(float(outputformquestion),0),0,div(float(outputformquestion),29.06))
    use float or integer if output in forms is a string to convert to number.
  • MB-26072021-0 Profile Picture
    MB-26072021-0 6 on at
    Need help using Excel formulae in "Add a row" flow
    @Robby_WW - Thanks for that. Yes, that's what we ended up doing, though it's not optimal to have the constants embedded in the flow like that when they will probably change periodically. But it works, so that's progress.
     
  • MB-26072021-0 Profile Picture
    MB-26072021-0 6 on at
    Need help using Excel formulae in "Add a row" flow
    Thank you for this advice! I will try it and confirm whether it works. To be clear, I'm aware that Forms writes responses to an Excel file by default. I needed to write the responses to a workbook that contains multiple sheets where I control the columns and layout, hence the choice to use a live Excel file on SharePoint.

    Thanks,
    Michael
  • Suggested answer
    NsL Coder Profile Picture
    NsL Coder 214 on at
    Need help using Excel formulae in "Add a row" flow
    You are explicitly using row 2 as the formula for all rows added to the excel table. your flow is doing exactly what you instructed to do.
     
    Flow is going to input in what you provided as the value (or formula) for the field/column. It is like typing =IF($F2=0,0,($F2/29.06)) directly on every row in that column, which is always going to be $F2.
     
    Some Options:
    1. Don't use a new excel file and dont' use flow
      1. MS forms will always create an excel file to capture all answers to form question. You can find this excel file and simple add the calculated column in the table. Add the forumla in. Everytime a new response is submitted, the response will be added to the table and the formula will "carry" down properly
    2. Update your flow to explicitly provide the cell reference correctly
      1. at the start of the flow, do a list excel rows in a table, do a "length" expression on the returned array to know how many rows are already in the table. Then that "length" can be used in your reference:
        for example. if your table has 3 responses already, when you list excel rows in a table, it will have an array of 3 rows returned. using "add(length(array_return), 1)" you will get a "4" that you can use in your add a row to excel table action: =IF($F@{add(length(array_return), 1)}=0,0,($F@{add(length(array_return), 1)}/29.06))
    3. Update your flow to do the calculation in the flow and assign the calculated value as value into the column instead of formula

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Community Update 9/9/24…

Power Platform Community Update…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 140,614

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,336

Leaderboard

Featured topics