View Single Post
 
Old 04-02-2020, 11:56 PM
ArviLaanemets ArviLaanemets is offline Windows 8 Office 2016
Expert
 
Join Date: May 2017
Posts: 873
ArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud ofArviLaanemets has much to be proud of
Default

Quote:
Originally Posted by GraemeSS View Post
I will have another look at your solution if I ever get to warp speed
This isn't too difficult really. Formulas used in my example are ordinary Excel formulas. The main difference is, that they adjust automatically whenever data is added/deleted to/from table.

3rd formula is like I'd use before defined Tables feature was introduced. The dynamic named range nrData is defined (Formulas>Name Manager from menu). Select Name from leftmost column, and in field 'Refers to' you see the formula which defines the range. click on this formula, and in table on worksheet you see the datarange of table selected (dashed border).
The formula is '=OFFSET(Sheet1!$A$5;1;;COUNT(Sheet1!$A:$A);4)'. An ordinary Offset() formula.
Formula parameters:
1st is SheetName!$A$5. It sets anchor point for range definition to cell $A$5 on sheet with table (the anchor must be outside of datarange, so formula will not be broken whenever 1st row from datarange is deleted);
2nd is 1. It moves the top row reference of range you are defining from anchor's row to topmost row of a datarange in table;
3rd is empty, i.e. leftmost column of range you are defining remains same as anchor's column;
4th is COUNT(SheetName!$A:$A). It counts all numeric values in column A. Assumed there is no numeric values in this column except in table's datarange, and there is no entry in table where the value of Month is not numeric, this returns the number of rows in table. And in OFFSET(), it determines how many rows the range will have;
5th is 4. This determines, how many columns the range will have. It is possible to count header row entries here too using COUNTA(), but let's keep it simple.

A dynamic range defined in such way adjusts automatically whenever rows are added to table or deleted from it. And when you use in your other formulas this dynamic range instead references like 'SheeName!$A$6:4D7, then whenever the table is edited, you don't need to edit your formulas manually. Another bonus is, that you can give a meaningful name to every such range, so when you look at formulas, you don't need to navigate to source table to look, which kind of data your are using as source.

I defined 3 additional named ranges (nrMonth, nrVal3, nrVal4), which simply define separate columns of nrData as named ranges. And as nrData is dynamic, those 3 are dynamic too.

To calculate the percentage in D3, values of Val3 and Val4 from row with max value of month must be used. I used SUMIFS() to calculate those values (you can use here SUMIF() too, but I prefer SUMIFS() everywhere, as it is more universal).



1st formula for percentage uses defined Tables. You can define a table as Table (table must have a single header row!), selecting a single cell in table header or datarange, and then from menu Insert>Table. You can give defined Table a name.

A defined Table is essentially a dynamic named range (it expands automatically, whenever you add data into cells bordering with it) with special features. You can use special Table syntax in formulas, which refer to various elements of table (whole table, header row, datarange, column data, value in another column in same row, etc.). A specific Table feature is, that when whole column in Table contains same formula, then whenever rows are added, the formula expands to new rows automatically. And when in formlulas you refer to data in Table using only Table syntax, you can add and delete columns (when deleting, of-course you must not have references to this column in any of formulas!) freely, change Table name or Table column names, and change Table column positions (activating column, pressing Shift, and holding Shift down dragging column to new position) - in all formulas in workbook referring to Table all changes will be updated automatically.

Later you can access some Table features (Name, Size, etc) selecting any Table cell, and activating Design from menu.

Rest of it is essentially same as with Named Ranges.
Reply With Quote