Select Spreadsheet From Dropdown To Query In Formula - excel

I have a pretty extensive spreadsheet that stores data over many years, and to help culminate that data I have a had to make multiple summary pages to calculate the data one for each year. I want to instead make a single sheet that will summarize the data and the user can simple select the year they want to view from a drop down menu and all the formulas will automatically calculate the new data. From what I can tell this can be done by using the "indirect" function but I cannot get it to work and am starting to think that function will not work because of the way the formula works. Does anyone have a working method that will generate the desired results.
Manual Formula
=SUMPRODUCT((MONTH('W.A.R. 2016'!$A4:$A369)>=1)*(MONTH('W.A.R. 2016'!$A4:$A369)<=3)*('W.A.R. 2016'!$A4:$A369<=TODAY())*(ISNUMBER(FIND("Work",'W.A.R. 2016'!B4:B369))+(ISNUMBER(FIND("Wrk/Lve",'W.A.R. 2016'!B4:B369))/2)))
Formula im working on.
=SUMPRODUCT((MONTH(INDIRECT("'("&O2&")'!$A4:$A369"))>=1)*(MONTH(INDIRECT("'("&O2&")'!$A4:$A369"))<=3)*(INDIRECT("'("&O2&")'!$A4:$A369")<=TODAY())*(ISNUMBER(FIND("Work",INDIRECT("'("&O2&")'!$A4:$A369")))+(ISNUMBER(FIND("Wrk/Lve",INDIRECT("'("&O2&")'!$A4:$A369")))/2)))
In theory I cannot see why its not working but I think it the way indirect pulls the data.

I can spot a couple of issues.
This has unnecessary brackets around the sheet name:
INDIRECT("'("&O2&")'!$A4:$A369")
It will produce a string like: '(W.A.R. 2016)'!$A4:$A369
You just want to use:
INDIRECT("'" & O2 & "'!$A4:$A369")
There is some inconsistency in your formulas
The first formula searches for "Work" in B4:B369 and "Wrk/Lve" in B4:B369, whereas the second formula has the ranges swapped around.
The best advice I can give on trying to figure out where a formula is going wrong is using the Evaluate Formula tool.
Select the cell that has the formula, go to the Data tab on the ribbon and click Evaluate Formula. It will pop up a dialog that allow you to step through each part of the formula as it calculates. From there you should be able to see what's going wrong.

Related

AGGREGATE formula not automatically calculating when written to results spreadsheet

I have a python 3.7 script that has been developed using the OPENPYXL (v2.5.10) library to take data from a number of excel workbooks, to process that data and then to write to a separate excel workbook. The results workbook contains around 100 named ranges and numerous formula which all work as expected including automatically calculating when the workbook is opened in excel.
I am having trouble with one particular formula group which includes the AGGREGATE function. In this case the formula writes to the results workbook, to the correct cell and in the correct form. While other formulas show the resulting value on opening the workbook, this sequence of formulas only show a result if you select the cell, place the cursor in the formula bar (as if you are editing the formula) and then you push the enter/return key. No change or edit is made to the formula. Once you have done this the formula works as expected.
I have tested this on both the latest macOS and windows versions of excel and I get the same behaviour. I should add that trying the 'calculate now', CtrlShiftAltF9, and 'calculate sheet' options do not have any impact. The only time the formula calculates is if you use the enter/return key.
The code that writes the formula is:
activeSheet.cell(row, col).value = f"=IFERROR(INDEX({rngData}, AGGREGATE(15,3,({rng}={cellRef})/({rng}={cellRef})*ROW({rng}),{nth}),{colIndex}),\"\")"
which gives, for example, a correct result in the excel workbook cell as:
=IFERROR(INDEX(_monthAgedDebt_Data, AGGREGATE(15,3,(_monthAgedDebt_ProjectNumbers=$L$4)/(_monthAgedDebt_ProjectNumbers=$L$4)*ROW(_monthAgedDebt_ProjectNumbers),1),6),"")
So in summary:
the code works as it writes the correct formula to the correct cell and in the correct form
in excel the formula does not automatically calculate but only works if you edit the formula in the cell, make no changes, and push enter/return to exit the edit
Is it an issue with AGGREGATE producing an array result? I chose this form of formula principally because you do not need a CTL-SHIFT-ENTER to make it work. If you enter it directly into a cell in excel you can enter it as a normal formula.
I haven't been able to find help on stack overflow other than this one. However, the solution proposed here doesn't work either.
This question poses a similar issue but has no relevant responses.
This question may hold a clue but I don't seem to be able to make that work as well.
Any thoughts on how to fix this issue appreciated. I am not sure if it is an openpyxl issue or an excel issue and am not sure what else to test.
All - the final answer for completeness.
It turns out that the key to solving this issue lay with OPENPYXL and that the guidance provided in the answer by Charlie Clark to this
question
was correct. I had initially applied the solution incorrectly.
I changed the formula to:
activeSheet.cell(row, col).value = \
f"=IFERROR(INDEX({rngData}, _xlfn.AGGREGATE(15,3,({rng}={cellRef})/({rng}={cellRef})*ROW({rng}),{nth}),{colIndex}),\"\")"
by adding in the '_xlfn.' to the front of the AGGREGATE function statement.
The excel spreadsheet now works as expected without the need to edit the cell containing the formula.

Formulas within a reference

I'm fairly new to excel but have been learning lots. Please go easy on me.
Have 30,000 pieces of data, and constantly filtering this data set. As such, all my formulas constantly need to be updated to the new range (for example, a filter may change my range from B7000:B9000 from B1:B30000). I was able to make it so I can retrieve the row numbers for the first and last visible column.
I was hoping to be able to reference this within my cells to expand my range. What I tried (just as an example),
=INDEX(Helper!D3:Helper!E3),MATCH... (rest of the formula is correct)
In the Helper Spreadsheets for D3 I have
=Concatenate("'Sheet 1'!U"&D2)
Where, D2 is the formula I have used to grab my first visible row. In this case my D2 displays 7000
Is this doable or am I totally approaching this wrong? I've seemed to hit a brick wall and I can't figure out how to get this to work. Thanks again.
EDIT:
I am trying to use index and match on a range of cells to populate a fairly large table. Problem is range keeps changing every time I filter data. So I have 30 iterations of this data I need to get through in an already fairly complex algorithm i'm running. I was hoping to save a few steps by having my formulas auto expand depending on the filter, which would save me lots of headache as right now I have to go through and edit each formula by hand to the range the filter sets.
I thought I had it figured out by getting a way to grab the 1st and last visible column, however now I can't enter those into a reference as a formula for example as in the case above.

Excel SUM COUNTIFS from different tables and futureproofing

I'm practising MS Excel skills. I have a workbook in which I want to analyses data from different tables.
Each worksheet contains a table with the information from the year. So in worksheet "2017" I have a table named "Table2017". I have this for each year (starting 2015).
After a some research, I finally found a way to count how many times something in a certain place happened.
=SUM(COUNTIFS(Table2018[Place];B3;Table2018[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2017[Place];B3;Table2017[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2016[Place];B3;Table2016[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2015[Place];B3;Table2015[Activity];{"Paid";"Awarded"}))
This works perfectly. It will calculate how many times per place a paid service or an awarded (gifted/sponsored) service was delivered. In the B column, I have a list of places (hence the B3 reference), so after completing the formula, I can select the cell and enlarge/drag to copy it to the rest of the column and apply for every place.
However, the formula is really long and every year upon creating a new worksheet, I need to add a new part to the formula.
Is there a way to compact this? And ideally have the formula search for every table that has the relevant information (like: "Table20??" or "Table 20*"), go in and count the times my conditions are found?
I hope my question is clear enough.
Thanks in advance!
P.S. I have zero experience in VBA/VBS, so I'm hoping to realize this in a normal formula.
There are ways to make it more compact, but they will necessarily make the function more complicated, so it wont be any easy win. See for yourself:
you basically need to be able to cycle through the years inside formula without creating custom formulas. One way to do this is to use ROW inside INDIRECT function. This way you can replace multiple
Table2015[Place]
with one array function containing
INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]")
as it is an array function it will essentially cycle through the cells in the ROW function creating Table2015[Place], Table2016[Place], Table2017[Place] and Table2018[Place]. Your whole formula would look something like this
=SUM(COUNTIFS(INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]");B3;INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Activity]");{"Paid";"Awarded"}))
and it must be entered using ctrl+shift+enter (you will see {} brackets around the function). This should work to make the function smaller and you will need only to change the cell reference each year instead of adding another sum, but the question is if the separate sums are not easier to read and maintain.

(excel) sumproduct multiplying with another sheet

i have a little problem with final formulas in one of my column. How to start. maybe i will explain what i have a then what i want.
i have an excel worksheet with 3 sheets. i want to record goods and what are these goods made of. first is sheet called Goods where is possible to put number of goods i want to make. In this case i want to make 1x sandwich1 and at the same time 3x sandwich2. i dont want make sandwich3 this time.
Second sheet is Matrix sheet where I record every good and what it is made of. This sheet is basic sheet and all other sheets take list of goods (resp. ingredients) from this sheet. Simply when i want to make sandwich1 i look at matrix and know that i need 1x1pc of egg + 1x5g of cheese. And for 3x sandwiche2 i need 3x10g of sausages.
Final sheet is called Ingredients. It is a list of used ingredients from Matrix sheet (exactly same order) to make these sandwiches. I want to fill formulas into column B which would go through one ingredient ofter ingredient and count needed amount of it. So it would look into matrix in the same row and where there is some number it would multiply with number of items from Goods sheet. The list of goods is also in the same order as in the matrix sheet.
I hope you understand now what i want and will try to help me. I think there will be SUMPRODUCT, SUMIF and maybe INDERECT functions but i am not that skilled in excel
thanks for any suggestions
You can use MMULT function here - it's an "array formula" which you need to enter in a range. You can do that like this:
In Ingredients worksheet enter this formula in B2
=MMULT(Matrix!C2:E4+0;Goods!B2:B4+0)
[I'm assuming you have a European version of Excel where ; is used to separate arguments]
Now select the whole range B2:B4, press F2 key to select formula and hold down CTRL and SHIFT keys and press ENTER. This "array enters" the formula in the range and you should now see curly braces like { and } around the formula and also the correct results.
You cannot change part of that array now, only the whole thing
Note that I'm assuming that the contents of Goods!A2:A4 will be the same as Matrix!C1:E1 and in the same order. You can extend the ranges to be as large as you like as long as that principle still holds
I suspect that this is an issue of "when all you have is a hammer, every problem is a nail". For reasons known only to you you are using a spreadsheet to solve a problem that databases were made to do. Any solution to this problem in a spreadsheet will be entirely dependent on the integrity of your data - add another column or get things out of order and it will fail.
That said, what you have in your link is effectively a pivot table and what you need is the unpivoted version of this - the instructions for getting this are here.
When you have that, you can use the various database functions in excel to get your answer.

Concatenate Formula (Getting a #REF Error)

Afternoon all :)
This is kind of a little difficult to explain but ill happily clarify where ever it is needed. Thank you for taking the time to read this post ^^ Here goes..
I am currently creating a spreadsheet that is been extracted from the database whereby I am tasked to concatenate data from 2 adjacent cells. I change the database on a frequent basis adding or removing data wherever necessary so the range of data is always different. To concatenate the two cells I use the following formula:
e.g: =IF(ISBLANK(B8&H8),"",B8&H8)
This formula works out great when im dealing with increasing amounts of data as I can simply drag the formula down as far as i want and i know that it will pick up the formula whenever I refresh the database without the need of seeing value errors when the formula ends up referring to a blank cell. The snag here (and my query as well) is if I have less data then before the formula within the last set of cells looks something like this:
e.g: =IF(ISBLANK(#REF!&#REF!),"",#REF!&#REF!)
I have dealt with #REF before in other spreadsheets whereby I simply used a ISERROR in the statement but I dont know if there is a possible way of including this within my formula. I need the ISBLANK there so I have more control and dont have to drag the formula as often.
If there is a better way around this or a way to amend the current formula Id appreciate the help :)
The only way you are going to get something like this:
=IF(ISBLANK(#REF!&#REF!),"",#REF!&#REF!)
in the formula bar is if you(or the system you are using) are somehow deleting the cells that were originally referenced. This should be avoidable. You can clear the cells referenced instead of deleting them completely - then you won't get this error - and your formulas will remain intact. Now you can certainly use the formulas provided in the comments to hide the errors - but the root of your problem seems to me to be that the errors are occuring in the first place. Good Luck.

Resources