Is there any option to do FOR loop in excel? - algorithm

I have an excel that I'm calculating my Scrum Task's completed average. I have Story point item also in the excel. My calculation is:
Result= SP * percentage of completion --> This calculation is for each row and after that I sum up all result and taking the summary.
But sometimes I am adding new task and for each task I am adding the calculation to the average result.
Is there any way to use for loop in the excel?
for(int i=0;i<50;i++){ if(SP!=null && task!=null)(B+i)*(L+i)}
My calculation is like below:
AVERAGE((B4*L4+B5*L5+B6*L6+B7*L7+B8*L8+B9*L9+B10*L10)/SUM(B4:B10))

First of all, AVERAGE is not doing anything in your formula, since the argument you pass to it is just one single value. You already do an average calculation by dividing by the sum. That average is in fact a weighted average, and so you could not even achieve that with a plain AVERAGE function.
I see several ways to make this formula more generic, so it keeps working when you add rows:
1. Use SUMPRODUCT
=SUMPRODUCT(B4:B100,L4:L100)/SUM(B4:B100)
The row number 100 is chosen arbitrarily, but should evidently encompass all data rows. If you have no data occurring below your table, then it is safe to add a large margin. You'll want to avoid the situation where you think you add a line to the table, but actually get outside of the range of the formula. Using proper Excel tables can help to avoid this situation.
2. Use an array formula
This would be a second resort for when the formula becomes more complicated and cannot be executed with a "simple" SUMPRODUCT. But the above would translate to this array formula:
=SUM(B4:B100*L4:L100)/SUM(B4:B100)
Once you have typed this in the formula bar, make sure to press Ctrl+Shift+Enter to enter it. Only then will it act as an array formula.
Again, the same remark about row number 100.
3. Use an extra column
Things get easy when you use an extra column for storing the product of B & L values for each row. So you would put in cell N4 the following formula:
=B4*L4
...and then copy that relative formula to the other rows. You can hide that column if you want.
Then the overal formula can be:
=SUM(N4:N100)/SUM(B4:B100)
With this solution you must take care to always copy a row when inserting a new row, as you need the N column to have the intermediate product formula also for any new row.

Related

Return column headers (columns B onwards) based on a text value in Column A and number value in other columns - in a Google spreadsheet

I have a matrix - 1,172 words down column A, then the same 1,172 names across row 1. Then each word is cross-referenced with all the other names to give a similarity score (this is already done).
In another sheet, I want to look up a word, and return all the words with which it has a certain similarity score - in this case, greater than or equal to 0.33. I attach a MWE, in which I give an idea of the answer I am looking for by looking it up manually.
I think it's some sort of reverse lookup. As in, instead of finding the value corresponding to a particular row and a particular column, it's finding the column based on value in the main sheet and row. I'm just really stuck at this point and would massively appreciate some help. Thanks! MWE here
If your words on the second sheet are in the same order then:
=IFERROR(TEXTJOIN(", ",,FILTER(Scores!B$1:W$1,(Scores!B2:W2>=0.33)*((Scores!B2:W2<1)))),"-")
Drag down.
Explanation:
Filter the values from row 1 according to the similarity score condition, using FILTER.
Concatenate the filtered values using TEXTJOIN.

ARRAYFORMULA summing column with previous recursively for all columns

Let's say my formula is in D2. I want to sum the value from previous column with another sheet column and do it for all rows, I can do the following:
=ARRAYFORMULA(C2:C+AnotherSheet!D2:D)
Now I would like the next column to do the same:
=ARRAYFORMULA(D2:D+AnotherSheet!E2:E)
How would I set it up, so it works for all columns without manually copy pasting this formula to the next column.
This quick and dirty brute force formula might be some help, depending on how many columns you need. Try this:
=ARRAYFORMULA({C2:C+Sheet2!D2:D,
C2:C+Sheet2!D2:D+Sheet2!E2:E,
C2:C+Sheet2!D2:D+Sheet2!E2:E+Sheet2!F2:F,
C2:C+Sheet2!D2:D+Sheet2!E2:E+Sheet2!F2:F+Sheet2!G2:G,
C2:C+Sheet2!D2:D+Sheet2!E2:E+Sheet2!F2:F+Sheet2!G2:G+Sheet2!H2:H})
It wouldn't be too hard to automatically generate the full formula you need, if your number of columns isn't changing all the time.
But I imagine someone will come up with an elegant formula to somehow do the same thing. Let us know if this helps.

First in first out inventory (FIFO) formula very slow calculation

I have a sheet including product transactions from inventory to another and from supplier to another, I import formula for FIFO evaluation from excel sheet to google sheet, but when I populate that formula to all fields sheet get very slow.
Below the link for my sheet.
This is One of formulas
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUM(--IF(MMULT(--(ROW(F$17:F18)>=TRANSPOSE(ROW(F$17:F18))),--IF(E$17:E18=N19,F$17:F18,0))<SUMIF(N$18:N19,N19,O$18:O19),1,0))), 1, 1)
and
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUMPRODUCT(--IF(OFFSET(E$17,,,V19+1)=N19,1,0),OFFSET(F$17,,,V19+1),OFFSET(H$17,,,V19+1))-SUMIF(N$18:N18,N19,Z$18:Z18)), 1, 1)
and
=ARRAY_CONSTRAIN(ARRAYFORMULA((SUMIF(N$18:N19,N19,O$18:O19)-SUMPRODUCT(--IF(OFFSET(E$17,,,V19+1)=N19,1,0),OFFSET(F$17,,,V19+1)))*OFFSET(H$17,V19,,,)), 1, 1)
and finally
=IF(SUMIF(N$18:N19,N19,O$18:O19)>SUM(E$18:E19,N19,F$18:F19),MAX(SUMIF(E$18:E19,N19,G$18:G19)-SUMIF(N$18:N18,N19,P$18:P18),0),Y19)
https://docs.google.com/spreadsheets/d/1xJxCipSh-Q5ltSaGo-kpEPomrZdAI1T8PDH57rc-sOw/edit?usp=sharing
Update....
Formula in column H
=IF(F19=0,0,G19/F19)
Replaced With
=ARRAYFORMULA(IF(LEN(F19:F), IF(F19:F=0, 0, G19:G/F19:F), ))
Formula In Column P
=Z19
Replaced with
=ARRAYFORMULA(IF(LEN(O19:O), IF(O19:O=0, 0, Z19:Z), ))
Formula In column O
=P19/O19
Replaced with
=ARRAYFORMULA(IF(LEN(O19:O), IF(O19:O=0, 0, P19:P/O19:O), ))
But still those formula need help with
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUM(--IF(MMULT(--(ROW(F$17:F18)>=TRANSPOSE(ROW(F$17:F18))),--IF(E$17:E18=N19,F$17:F18,0))
=ARRAY_CONSTRAIN(ARRAYFORMULA(SUMPRODUCT(--IF(OFFSET(E$17,,,V19+1)=N19,1,0),OFFSET(F$17,,,V19+1),OFFSET(H$17,,,V19+1))-SUMIF(N$18:N18,N19,Z$18:Z18)), 1, 1)
=ARRAY_CONSTRAIN(ARRAYFORMULA((SUMIF(N$18:N19,N19,O$18:O19)-SUMPRODUCT(--IF(OFFSET(E$17,,,V19+1)=N19,1,0),OFFSET(F$17,,,V19+1)))*OFFSET(H$17,V19,,,)), 1, 1)
=IF(SUMIF(N$18:N19,N19,O$18:O19)>SUM(E$18:E19,N19,F$18:F19),MAX(SUMIF(E$18:E19,N19,G$18:G19)-SUMIF(N$18:N18,N19,P$18:P18),0),Y19)
Regards
The sheet FIFO has a very long "formula chain" on column H (and may other columns too) from row 19 to row 5395. By formula chain I'm referring to a formula including relative references that was filled down/right so the differences in A1 Notation between a formula an the next are just the relative references but in R1C1 notation the formulas will look the same way.
To improve the performance of your spreadsheet you should reduce the number of formulas. If you don't need so many rows, try deleting the unnecessary rows. If that isn't enough, or you are looking for an optimal performance, replace formula chain by an array formula when this is possible or use Google Apps Script
NOTES
To make an optimal use of you web browser / device / network
resources
avoid the use of open references or enclose them inside ARRAY_CONSTRAIN function to return only the required values.
on Google Apps Script, avoid or keep the calls to the Spreadsheet Service at the execution time at minimum, specially avoid the to make calls to the Spreadsheet Service on loops, like using a for loop to edit one cell at a time.

Tableau - Calculated fields / grouping / Custom Dim

Tableau:
This may seem simple, but I ran out of the usual tricks I've used in other systems.
I want a variance column. Essentially adding a member 'Variance' to the Act/Plan dimension which only contains the members 'Actual' and 'Plan'
I've come in where the data structure and reporting is set up like so:
Actual | Plan
Profit measure
measure 2
measure 3
etc
The goal is to have a Variance column (calculated and not part of the Actual/Plan dimension)
Actual | Plan | Variance
Profit measure
measure 2
measure 3
etc
There are solutions where it works for one measure only, and I've looked into that.
ie, create calculated field as such
Profit_Actual | Profit_Plan | Variance
You put this on the columns, and you get a grid that I want... except a grid with only 1 measure.
This does not work if I want to run several measures on rows. Essentially the solution above will only display the Profit measure, not Measure 1_Actual , Measure 2_Plan etc.
So I tried a trick where I grouped a the 3 calculated measures, ie Profit_Actual | Profit_Plan | Profit_Variance as 'Profit_Measure'
Created a parameter list - 'Actual', 'Plan', 'Variance'
Now I can half achieve my goal, by having the parameter on columns and the 'Profit Measure' on Rows (so I can have Measure 123_group etc down on rows too). Trouble is, I found that parameters are single select only. Only if it can display all options in the custom paramater at once, I would've solved my problem.
Any ideas on how I can achieve the Variance column I want?
Virtually adding a member to a dimension/Calculated fieds/tricks/workaround
Thank you
Any leads is appreciated
Gemmo
Okay. First thing, I had a really hard time trying to understand how your data is organized, try to be more clear (say how each entry in your database looks like, and not how a specific view in Tableau looks like).
But I think I got it. I guess you have a collection of entries, and each entry has a number of measure fields (profits and etc.) and an Act/Plan field, to identify whether that entry is an actual value or a planned value. Is that correct?
Well, if that's the case, I'm sorry to say you have to calculate a variance field for each dimension. Think about it, how your original dataset is structured. Do you think you can add a single field "Variance" to represent the variance of each measure? Well, you can, store the values in a string, and then collect it back using some string functions, but it's not very practical. The problem is that each entry have many measures, if it had only 1 measure, than 1 single variance field would suffice.
So, if you can re-organize your data, what would be an easier to work set (but with many more entries) is something with the fields: Measure, Value, Actual/Plan. The measure field would have a string to identify what you're measuring in that entry. Value would be a number to represent the actual measure. And the Actual/Plan is the same. For instance:
Measure Value Actual/Plan
Profit 100 Actual
So, each line in your current model would become n entries, where n is the number of measures you have right now. So a larger dataset in a way, but easier to work with. Think about, now you can have a calculated field, and use some table calculations to calculate the variance only for that measure and/or Actual/Plan. Just use WINDOW_VAR, and put Measure and/or Actual/Plan in the partition.
Table calculations are awesome, take a look at this to understand it better. http://onlinehelp.tableausoftware.com/current/pro/online/en-us/help.htm#calculations_tablecalculations_understanding_addressing.html
I generally like to have my data staged such that Actual is its own column and Plan is its own column in the data being fed to Tableau. It makes calculations so much easier.
If your data is such that there is a column called "Actual/Plan" and every row is populated with either "Actual" or "Plan" and there is another column called "Value" or "Measure" that is populated with the values, you can force Tableau to make them columns assuming you can't or won't rearrange your data.
Create a calculated field called "Actual" with the following calc:
IF [Actual/Plan] = 'Actual' THEN [Value] END
Similarly, create a calculated field called "Plan" with the following calc:
IF [Actual/Plan] = 'Plan' THEN [Value] END
Now, you can finally create your "Variance" and "Variance %" calculations (respectively):
SUM([Actual]) - SUM([Plan])
[Variance] / SUM([Plan])

Is it possible to create a table made up of multiple what-if scenario results?

I'm going to describe my goal in steps because I think that might be the easiest way to explain it. This is what I'm trying to do:
1) Create a template that has various calculations on it. On this template, 1 specific cell is left blank. The calculations will change depending on what's in this cell (I'll refer to this as the special cell).
2) There's one final figure behind these calculations that's important. What I want to do is create a list with every possible final figure and in an adjacent cell, list the value of the special cell that gives this final figure.
The problem is Excel for Mac 2008 doesn't use macros or VBA. In my Windows version of Excel, this is just a simple function. But on Excel for Mac 2008, I'm not sure at all how to tackle this. The only solution I can think of is to create one sheet for every possible value of the special cell, with all the calculations done specifically for that value of the special cell. Then I could just link each final figure/special cell to a main page so all the information is together. However, there are roughly 400 values the special cell can take, and I really don't want to create 400 different sheets. Does anybody know how I can do this?
Also, just as a note in case this is easier to visualize what I mean, I'm basically trying to run multiple what-if scenarios and collect one specific number from each of these scenarios.
Here's an example of the processes involved. I should mention here that there are actual 2 different special cells, I wrote 1 in the original description because I'm assuming the idea would be the same to do 2:
1) The main template sheet is located on Sheet A
2) There are 10 slots for store names
3) Each store has a rate, the rate is found by applying a vlookup which looks up the special cell 1 and where the array table is located on Sheet B
4) Each store also has an index number (referred to as index)
5) Each store has a calculation which is index * special cell 2 (referred to as calc1)
6) Each store has another calculation which is rate * num1 (referred to as calc2)
7) Each store has another index number (referred to as index2)
8) Some of the index2 values have to be multiplied by calc2, the rest will stay the same (referred to as calc3)
9) A summation has to be done, summing all the calc2 values to result in sum1
10) A summation has to be done, summing all the calc3 values to result in sum2
11) The final figure is sum1 + sum2
It sounds like you could create 400 rows where each row is a what if scenario. Then next to each row you could take an input and an output, and graph accordingly.
Update
Per your description so far I've created the attached workbook with some formulas to put you in the right direction:
https://dl.dropbox.com/u/19599049/120813_2c.xlsx
It calculates the sum1 and sum2 For 10 stores based on the 2 inputs.
Note that I colored which cells were ending up in which final output.
yellow = original sum1/sum2
blue = array formula version of sum1/sum2
green = data used in both.
I did this to point out that while this example workbook seems to follow all 11 of your rules. the input 2 doesnt appear to be included in the final outputs of my mock-up version for some reason.
Either way this should serve as a good basis to get you started. And I can modify it if you continue to include more details.

Resources