How can you dynamically change an Excel table column reference? - excel

I have multiple Excel tables storing numeric values. I am summarizing a rows values like this:
=+SUM(Query_Current_Year[#[Begin_Balance]:[Balance_Period6]])
Every month, I need to update each table like this:
=+SUM(Query_Current_Year[#[Begin_Balance]:[Balance_Period7]])
Is there a way to store the current column string in a cell like A1 with the value of "Balance_Period6", then reference cell A1? Each month, I would only need to update one field.
I can think of numerous reasons to need this, so I am certain there is a solution.

While I don't understand every detail of the logic, this is the fix.
'''=SUM(INDIRECT("_2360_2860["&A7&"]"))'''
You need to wrap the full table reference in an indirect function. I was hoping for something more readable but it works.

Related

Is it possible to create a SUM of all of the unique names 2 dimensionally and their value like in the example below?

I am trying to find a function that will look through all of the sheet to find unique names and sum the value that was assigned at a specific date like below: (End result should be like the summary) - I am restricted to use this format and can't have all the names under one column and dates under another.
A simply old fashion Sumif function is enough.
In I2, formula copied down :
=SUMIF(A:E,H2,B:F)
"I am trying to find a function that will look through all of the sheet to find unique names and sum the value that was assigned"
Assuming:
You indeed don't know the names beforehand (and over the course of 800+ columns and idemt dito rows (or more), it's "impossible" to write these out beforehand);
You have an arbitrairy range (of up to 800 columns and many rows);
Access to the BETA-channel of ms365.
Formula in H3:
=LET(X,WRAPROWS(TOCOL(A3:F5,1),2),Y,INDEX(X,0,1),Z,UNIQUE(Y),HSTACK(Z,BYROW(Z,LAMBDA(a,SUM((Y=a)*INDEX(X,0,2))))))
Note: The above is based on the assumption you don't know the unique names up front (as stated in the body of your question). Admittingly, if these are known, there are other/better answers.
So laid the data out like so and used sumifs():
SUMIFS($C$2:$C$8,$B$2:$B$8,F2)
Will let you consider adding a date control: prior to, equal to or after...
If you say you cannot change the source data, then make a data sheet to copy all the data, do the results like I show then link the results over...
So if you have to keep the format (instead of copying the data as already suggested - perhaps you missed that as you did not address that in your comment) then you could use sumifs() multiple times like so:
And just for fun playing with date control, still using your format:

Dynamic summing with two-way criteria in Excel

Basically I have a table like this:
The Names are filtered from another table and are dynamic.
I am trying to sum the values based on two criteria ("Duration" and "Day of week"), like this:
=SUMIFS($B5:$E5,$B$2:$E$2,G$2,$B$3:$E$3,G$3)
This gives a correct result, but I want the formula to dynamically update, based on the dynamic formula that contains the names. So I tried this:
=IF(A5#<>0,SUMIFS($B5:$E5,$B$2:$E$2,G$2,$B$3:$E$3,G$3),0)
This goes way down the table, but it always returns the sum of the first row.
Is anyone aware of a solution to this?
Just posting an answer so I can include a screenshot - illustrating that the formula
=SUM(INDEX($A$5#,,MATCH(G2&G3,$A$2:$E$2&$A$3:$E$3,0)))
does produce a valid result

How can I make my function reference all the cells in my column that are being used instead of just having a broad function?

I have many formulas that reference a large list and at the time I just have them to 1000 to make it easy. There will come a day that I will surpass 1000 and I don't want to have to continuously update the function but at the same time I don't want to have an excessive range.
The following function is in cell CM4 and I have data in cells CM11:CM52 and each day one more gets added at the bottom. What kind of function could I use to just take the average of CM11:CM52 that will reference CM11:CM53 tomorrow and so on and so on?
The following formula is a simple one that is in my worksheet:
=AVERAGE(CM11:CM1000)
Many formulas do not have a cost to using full column references. AVERAGE() is one of them so there is no problem using
=AVERAGE(A:A)
Or if you want to start on a certain row:
=AVERAGE(CM11:CM1048576)
For those formulas that do matter ie Array Types then we can make it dynamic with INDEX/MATCH
=AVERAGE(CM11:INDEX(CM:CM,MATCH(1E+99,CM:CM))
If the column in question is text then use "zzz" instead of 1E+99
I would suggest adding your data to a table (insert>table). This will allow the formulas to update automatically.

Using tables and column titles in VLOOKUP

I'm having a very difficult time with transitioning my VLOOKUP statement from simply referencing sheets and ranges (which work like a charm), to instead using table and column names.
I'm trying to make the VLOOKUP a bit more robust as the sheet where it is pulling from will constantly be changing data, so column numbers will change frequently. Thus, I'd like to just reference a column by its name.
I have converted the source data sheet to a table.
I have named all columns appropriately and double checked spelling.
This VLOOKUP works great (currently):
=VLOOKUP(E6,'Costs'!$A$2:$AE$84,19,FALSE)
However, what I would like to do is make it look this:
=VLOOKUP(E6,tblCosts[Order Number],tblCosts[June 2017], FALSE)
I have been fiddling with also trying to use MATCH which is not working either:
=VLOOKUP(E31,tblCosts[Order Number],MATCH(F4,tblCosts[June 2017],FALSE),FALSE)
UPDATE
This formula now works but it is returning the order number...not the cost for the month.
=VLOOKUP(E31,(tblCosts[Order Number]),(tblCosts[June 2017]),FALSE)
Normally I would keep trying this myself...but I am feeling overwhelmed and have been trying for hours. Any advice would be great.
Thank you!!
This should work for you:
=VLOOKUP(E31,tblCosts[#All],COLUMN(tblCosts[Jun-17]),false)
The COLUMN(TblCosts[Jun-17]) returns the column number of the field you want.
The VLookup searches the first column of tblCosts[#All] - (all the data in the table) for the data (in E31) and returns the data in the column you want.
This formula will continue to work even if you add columns or rows to the data.
Make sure that any heading which looks like a date in your spreadsheet eg "Jun-17" is stored as Text and not as a Date, as it will not match the string "Jun-17" when you use VLookup.
=VLOOKUP(E37,tblCosts[#All],match("Jun-17", tblCosts[#Headers]),FALSE)
This match is looking for the column name in all column headers and will return the number of columns to the right of the first column rather than the column number in the sheet. This avoids having to use COLUMN(tblCosts[Jun-17]) - COLUMN(tblCosts[Order Number]) + 1 when your table doesn't start in column A.
Ref: https://www.excel-university.com/vlookup-hack-4-column-labels/

Excel index match multiple row results

I'm stuck on an Excel problem and am hoping someone can assist. I read through 10-15 topics that are similar, but I wasn't able to get anything to work. Here is where I'm at...
I have a large data set containing columns for Year, Name, Total 1, Total 2 (and 20+ other columns). The same names appear in multiple rows based on the yearly totals. On a separate sheet, I have another data set containing Name and would like to pull the data from sheet one into columns as shown below.
I have done this in the past using only one year as the initial data set with the following formula:
=INDEX(DATARANGE,MATCH([#Name],DATARANGE[Name],0),MATCH("Total 1",DATARANGE[#Headers],0))
The problem I am having is the result of adding multiple years of data to my 1st data set. Is there a way to match the row based on name and year and then return the results of the appropriate column?
=SUM(($A$2:$A$9=B$16)*($B$2:$B$9=$A17)*($C$2:$C$9))
Enter above in cell B14 as an array formula or below as standard
=SUMPRODUCT(($A$2:$A$9=B$16)*($B$2:$B$9=$A17)*($C$2:$C$9))
You can do the same for total 2 just replace Cs with Ds
And then drag right and down.
Change the first MATCH function to something like this:
=MATCH(1,INDEX(([#Name]=DATARANGE[Name])*([#Year]=DATARANGE[Year]),0),0)
so as part of your whole formula that would be this
=INDEX(DATARANGE,MATCH(1,INDEX(([#Name]=DATARANGE[Name])*([#Year]=DATARANGE[Year]),0),0)
,MATCH("Total 1",DATARANGE[#Headers],0))
Another way you can use for returning numbers only (as here) is like this: (with cell refs for simplicity).
=SUMPRODUCT((A2:A9=2013)*(B2:B9="name x")*(C1:D1="Total 1"),C2:D9)
If the presented data to be indexed is a table then
This
=MATCH(1,INDEX(([#Name]=DATARANGE[Name])*([#Year]=DATARANGE[Year]),0),0)
should be corrected to a proper structured reference of
#[Name]
Also since this is an array formula it may not work with structured references at all. You'd be better served with regular cell references. Also if it is not a table only cell references will work.

Resources