Automatically update formula after adding columns - google-sheets-formula

My issue has been dealt with in here but I can't think thru and apply it to my formula
How to automatically update formula when inserting columns.
I would really appreciate some help here guys. Thank you!!!
This is the formula I got:
=IF($A$14=NAMES!$W2;$D15;
IF($A$14=NAMES!$W3;$G15;
IF($A$14=NAMES!$W4;$J15;
IF($A$14=NAMES!$W5;$M15;
IF($A$14=NAMES!$W6;$P15;
0)))))
After inserting three more columns it has to go to:
=IF($A$14=NAMES!$W2;$D15;
IF($A$14=NAMES!$W3;$G15;
IF($A$14=NAMES!$W4;$J15;
IF($A$14=NAMES!$W5;$M15;
IF($A$14=NAMES!$W6;$P15;
IF($A$14=NAMES!$W7;$S15;
0))))))
Upon adding 3 more columns to the right, it looks up for the value in $A$14 and if that matches the one in NAMES!$W + i where i is the row incrementing by 1, then it returns a specific column in the same row# 15, be it $D15, $G15, $J15, always jumping three columns.
The 3 columns are automatically inserted via a trigger based on date/time in GAS but I was not able to make the formula automatically update via GAS.
I'm not even sure if this is possible.
Please help!
Thank you!
I write here again because the comment is too short:
You're right!
Here's the link to the Sheet with editor access.
https://docs.google.com/spreadsheets/d/1Qkb96SgZ4dLRBebgxEiNkYiZ4sTtps-ZbBtBtE4J5os/edit?usp=sharing
So basically, whenever a new year is created or 3 more columns are added the formulas in C15, C16 and C17 be updated automatically from
C15 =IF($A$14=Dates!$A2;$D15;IF($A$14=Dates!$A3;$G15;0))
to =IF($A$14=Dates!$A2;$D15;IF($A$14=Dates!$A3;$G15;IF($A$14=Dates!$A3;$J15;0;0)))
C16 =IF($A14=Dates!$A2;$D16+$E15+$B13;IF($A14=Dates!$A3;$G16+$H15;0))
to =IF($A14=Dates!$A2;$D16+$E15+$B13;IF($A14=Dates!$A3;$G16+$H15;IF($A14=Dates!$A3;$J16+$K15;0)))
C17=IF($A14=Dates!$A2;$D17;IF($A14=Dates!$A3;$D17+$G17;0))
to =IF($A14=Dates!$A2;$D17;IF($A14=Dates!$A3;$D17+$G17;IF($A14=Dates!$A3;$D17+$G17+J17;0)))
and so on...

Daniel, I've had a try, and have found a way to get part of your answer. I believe the rest of your problem could be solved in the same way. Look at tab Test-GK in your sample sheet. Your original formula is in C15; mine is in C19.
Both update as you change the value in B14.
I've used a formula to calculate which cell is needed to be used, instead of lots of IF statements. The formula is as follows.
=INDIRECT(ADDRESS(15;(MATCH(A14;Dates!$A$2:$A$15;0))*3+1;4))
This uses MATCH to obtain an 'offset' value for your date range from in your Date values.
Then it multiplies this by 3 to jump to the right column.
So for the first date range in your list, "a 31 de diciembre 2018", MATCH returns "1" (first date range in the list) times 3 plus 1 equals "4", which ADDRESS converts to column "D". The row is always 15 using your sheet.
So ADDRESS(15,1,4) returns D15.
And INDIRECT gets the value of D15.
I think the same principle could be used for the formula in C16. But I'm not as clear what that formula is doing. Does your script put a value into B13?
Let me know if this looks useful.
Update#1. I've got the formula (I think) to replace your formula in C16 as well now. Except for the third term, adding B$13, in only the first case? If necessary, this could be handled with one IF statement, to check if the data range is "a 31 de diciembre 2018".
Let me know how the B13 value is used...
Update #2. Also added a formula to replace your IFs in C17. Effectively the same, but used a CHOOSE function to select which terms get added together, instead of an IF. Maybe a bit clearer to maintain if you add more years to the date range.
Try this formula in C17 - double check the logic.
=CHOOSE(MATCH(A14;Dates!$A$2:$A$15;0); D17; D17+G17; D17+G17+J17; D17+G17+J17+M17; D17+G17+J17+M17+P17; D17+G17+J17+M17+P17+S17; D17+G17+J17+M17+P17+S17+V17; D17+G17+J17+M17+P17+S17+V17+Y17)
It's good to 2025, but if you need another five years or so, you can just make it longer. There is perhaps a way to build it dynamically, but I didn't have the time now for that.

Related

Multiple Search Key in a Matrix

I'm trying to solve this problem since some days now but it seems I have reached a dead end. Maybe someone would be able to help me.
I have two sheets. The first one contains the list of my clients and their delivery number depending of the weekday.
In my second sheet I would like to get the delivery number of the client (red cells) depending of the weekday I select (yellow cells).
I tried VLOOKUP formula, INDEX/MATCH, QUERY but I wasn't able to find a way to get the delivery number depending of the client's name and the weekday. I think the main issue is that in the first sheet the weekday is a column title.
Maybe the solution is simply to build my tables differently...
Thank you for your help
You can try something like this, assuming A2 and B2 the cells of first name and first day to look:
=INDEX(Sheet1!$1:$1000,MATCH(A2,Sheet1!$A:$A,0),MATCH(B2,Sheet1!$1:$1,0))
Or, if you want this same formula for the full column:
=byrow(A2:A,lambda(each,if(each="","",INDEX(Sheet1!$1:$1000,MATCH(each,Sheet1!$A:$A,0),MATCH(offset(each,0,1),Sheet1!$1:$1,0)))))
Also doable (are perhaps more simply) using a MAP/FILTER; with your 'Caption 1' table in Sheet1!A1:D4 and your 'Caption 2' table at the top-left of Sheet2, the following in Sheet2!C2 gives you the delivery number for a many names/days as you enter in the columns alongside:
=map(A2:A,B2:B,lambda(name,day,ifna(filter(filter(Sheet1!B2:D4,Sheet1!A2:A4=name),Sheet1!B1:D1=day))))
N.B. The IFNA blanks out errors for those rows where a Name/Day pair hasn't been entered yet. Extend the ranges in the filter to suit your real data.
all you need is simple vlookup:
=INDEX(IFNA(VLOOKUP(A9:A11&B9:B11,
SPLIT(FLATTEN(A2:A4&B1:D1&"​​"&B2:D4), "​​"), 2, )))

Reset count after a new month starts

I'm adding data to a spreadsheet and I want to do basic tasks programmatically.
Every time I add a date like 03/01/2022 the month cells updates to "March" with
ARRAYFORMULA(IF(E2:E = "","", TEXT(E2:E,"mmmm")))
So, I'm counting the entries per month like this:
I created a formula to make a sequence, but it'll go infinitely as per the number of rows, I'd like to reset the count when the Month cell is different than the previous one.
=SEQUENCE(ROWS(B2:B))
David, I assume "Month" is in column B and you want the sequence in column A under "No."
Try using this formula in A2:
=arrayformula(if(B2:B="",,countifs(B2:B,B2:B,row(B2:B),"<="&row(B2:B))))
Briefly:
uses the arrayformula so you don't have to copy down the formula
if(B2:B="",, takes care of any blanks
countifs() along with row() does the rest of the magic.
to see the role of row(), try using just countif(B2:B, B2:B). This will give the total number of occurrences of "January. "February", etc.
row() combined with "<="&row() makes sure that the formula counts occurrences above the current row only.
Watch out for year change. All "January" values across different years will be added to the sequence.
Good luck.

Power Query - conditional replace/clear entire cell in multiple columns

I'm trying to clear the entire cell if it doesn't contain a given keyword.
I've managed to do this for one column:
Table.ReplaceValue(#"PrevStep",each [#"My Column"], each if Text.PositionOf([#"My Column"],"keyword")>-1 then [#"My Column"] else null,Replacer.ReplaceValue,{"My Column"})
The problem is I need to iterate/repeat that step for a number of columns... the number of columns may vary and column names also may be different every time. I can have all those column names put into a list but I'm not able to use it.
The solution I'm looking for may look like this
for each ColNam in MyColumnsList
Table.ReplaceValue(#"PrevStep",each [#"ColNam"], each if Text.PositionOf([#"ColNam"],"keyword")>-1 then [#"ColNam"] else null,Replacer.ReplaceValue,MyColumnsList)
next
but this is not the VBA code but Power Query M - and of course the problem is with #PrevStep as I would see it like a recursions... again... do not know how to process.
Is the path I follow correct or should it be done some other way
Thanks
Andrew
Unpivot your columns to turn all the columns into two columns. Apply your replacement to the single value column then pivot it back into the original format

Pulling data from Crystal Reports

My data is stored in Oracle and the only way I can run a report with it is using Crystal Reports. I have a set of data that looks like this ,,,,,,,,,,1, or ,1,,,,,,, or ,1,,,,,1,,,,1,. There are more variations.
Each one means a value is true for a record. There are about 54 'ticks/commas' What I want is all records with the one at the X spot. So for one report I may want all records in the 10th spot that have a 1. There may be other times where I want the records where the 1 is after spot 36. I agree it will pull other records but the main once I want is the X spot.
How do I get this? I tried a Like command but that does not narrow the data down far enough. I am familiar with SQL but not Crystal.
Any help would be great. TIA
In Crystal, you might try setting up a Parameter Field to hold a numeric value (1 to 54) then use that in a formula as the Record Selection. You'll be prompted to enter the parameter when you run the report.
In record selection i was initially going suggest the following which would bring back all records with 1 in the 12 spot. But this makes it hard to bring back a range.
split({yourfield},",")[12] = 1
This will bring back the same
instr({#test},"1") = 12
Then for your suggestion above you could use the following to bring back any record if it has a one in any spot after 36
instr({#test},"1") >= 37
As long as there is only one 1 in the field you can use this for other ranges as well.
Actually I don't want to disturb both answerts by Clayton Morris and CoSpringsGuy hence posting my answer.
You need to combine both the solutions to get the desired result.
Create a number parameter and provide either 1 to 57 numbers or keep just a filed to enter desired number.
Now in record selection use the formula given by CoSpringsGuy
if instr({databasefield.column},"1") = {?Inputnumber} --parameter field
then {databasefield.column}

Can I compare values in the same column in adjacent rows in PowerPivot?

I have a PowerPivot table for which I need to be able to determine how long an item was in an Error state. My data set looks something like this:
What I need to be able to do is to look at the values in the ID and State columns, and see if the value in the previous row is ERROR in the State column, and the same in the ID column. If it is, I then need to calculate the difference between the Changed Date values in those two rows.
So, for example, when I got to row 4, I would see that the value in the State column for Row 3, the previous row, is ERROR, and that the value in the ID column in the previous row is the same as the current row, so I would then calculate the difference between the Changed Date values in Row 3 and Row 4 (I don't care about the values in any of the other columns for this particular requirement).
Is there a way to do this in PowerPivot? I've done a fair amount of Internet searching, and it looks like if it can be done, it would use the EARLIER or EARLIEST DAX functions, but I can't find anything that tells me how, or even if, this can be done.
Thanks.
Chris,
I have had similar requirements many times and after a really long time of trial-and-error, I finally understood how EARLIER works. It can be very powerful, but also very slow so always check for the performance of your calculations.
To answer your question, you will need to create 4 calculated columns:
1) Item Rank - used for ranking the issues with same Item ID
=COUNTROWS(FILTER('ID', EARLIER([Item ID]) = [Item ID] && EARLIER([Date]) >= [Date]))
2) Follows Error - to easily find issue that follows EROR issue
=IF([State] = "EROR",[Item Rank]+1)
3) Time of Following Issue - simple lookup so that you can calculate the different
=IF([Follows Error]>0,
LOOKUPVALUE([Date], [User], [User], [Item Rank], [Follows Error]),
BLANK()
)
4) Time Diff - calculation of time different for the specific issue
=IF([State]="EROR",
DAY([Time of Following Issue])-DAY([Date]),
BLANK()
)
With those calculated columns, you can then easily create a powerpivot table, drag State and Item Id onto the ROWS pane and then simply add Time Diff to Values. You will get an overview of issues that contain string "EROR" issue and the time it took to resolve them.
This is what it looks like in PowerPivot window:
And the resulting Pivot table:
You can download my Excel file here (2013).
As I mentioned, be careful with the performance as the calculated columns with nested EARLIER and IF conditions might be a bit too performance-demanding. If there is a smarter way, I would be very happy to see it, but for now this works for me just fine.
Also, keep in mind that all calculated columns could be nested into 1, but I kept them separated to make it easier to understand the formulas.
Hope this helps :-)

Resources