Removing INDIRECT from dynamic column selection - excel

I have researched thoroughly before posting and still can't figure this out.
I currently have a file that uses an INDIRECT logic to gather information from one worksheet to a summary worksheet. The file works perfectly as is. But I'm trying to make it more efficient as right now calculating times are huge due to so much volatility.
In the data worksheet I have a lot of columns, each with a concept and an account number assigned to it.
So, for example:
5014255 5324232 5566544
Name Store Salary Taxes Other Benefit P1 Weight P2 Weight
John Main 222222 50000 30000 0.4 0.6
Jane Annex 222224 50002 30004 0.3 0.7
Then in the summary page, I use a SUMPRODUCT to gather the information per store per account and separating by period, like this as:
Store Account Concept P1 P2
Main 5014255 Salary 88888.8 133333.2
Main 5324232 Taxes 20000.0 30000.0
Main 5566544 Other Benefit 12000.0 18000.0
Annex 5014255 Salary 66667.2 155556.8
Annex 5324232 Taxes 15000.6 35001.4
Annex 5566544 Other Benefit 9001.2 21002.8
This of course is just a basic example. The real file has several more validations and several categories of weights that are used for different accounts. In order to pull the information I have the following formula.
=IFNA(SUMPRODUCT(
INDIRECT(INDEX("'Sheet1'!"&ADDRESS(6,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4)&":"&SUBSTITUTE(ADDRESS(1,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4),"1","")&$AU$1,1,1)),
--(Sheet1!$C$6:$C$1754=2018),
--(Sheet1!$J$6:$J$1754=$I5),
IF($G5=1,Sheet1!$BN$6:$BN$1754,IF($F5=1,Sheet1!$BA$6:$BA$1754,Sheet1!$AN$6:$AN$1754))
),0)
The important piece of code is:
INDIRECT(INDEX("'Sheet1'!"&ADDRESS(6,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4)&":"&SUBSTITUTE(ADDRESS(1,COLUMN($A$5)+MATCH($N5,Sheet1!$1:$1,0)-1,4),"1","")&$AU$1,1,1))
This uses string manipulation to generate the column range according to the account number. So for example, the account number 5014255 would generate Sheet1!$C$6:$C$1754, so that the values in that column can be gathered according to weight and validations.
So, I'm trying to change the logic to remove volatiles. But so far I haven't been able to do it.
I basically need my summary to find the column where the account number is, so it can do the sumproduct calculations with that column.
Any ideas or suggestions on how to work around this?

To get the full column without volatiles use:
INDEX(Sheet1!$C$6:$E$1754,0,MATCH($N5,Sheet1!$C$1:$E$1,0))
This will return the correct column to the SUMPRODUCT formula

Related

Of the 10 individuals with the highest income, how many are married males?

Question --> Of the 10 individuals with the highest income, how many are married males?
I want to achieve the same in a single function.
Below is a database.
enter image description here
First I fetched data with Large and the applied vlookup and the used counifs to get the count.
enter image description here
enter image description here
You are close.
Why are you using IFERROR? Are there errors in the data or something else?
In the formula below, I used a Table and Structured references. An advantage is that the range references will automatically adjust. You can switch to normal addressing if you prefer.
I would use:
=COUNTIFS(myTable[Income],">="&LARGE(myTable[Income],10),myTable[Sex],"M",myTable[Married],"Yes")
With regard to your formula, you would think you could just SUM the results. Unfortunately, for any instance where there are duplicates (2 married men with same income in the top 10), your formula would return a 2 and not a 1 and the SUM would therefore be incorrect.
You can avoid that, with your approach, by converting any non-zero into a 1:
=SUM(--ISNUMBER(1/(COUNTIFS(myTable[Income],LARGE(myTable[Income],SEQUENCE(10)),myTable[Sex],"M",myTable[Married],"Yes"))))
However, I think my approach is simpler.

How to resolve Excel IF AND question query formula

Need help with a Excel formula.
I have two sets of data in two tables, with the same number of columns and rows.
One table has data for male, the other one for female.
Each table has a common definer (age). All the other data are different. All data are in numbers. Some are negative.
I aim to use a single cell to get a result coefficient used by a specific equation, and I need to channel the input data by two criteria. One is gender, the other one is age. I am trying the IF AND formula, but it is not working.
Here is an example.
age (D2) coefficient (D2-D4)
Table Female.
18-30 yrs 25
30-60 yrs 35
60-70 yrs 41
So here is the data to process:
D1 F
D2 29
D3 115
(MEANING Gender - female; age 29; weight 115 pounds)
I was trying the IF AND formula
=IF(AND(D1="F";D2>17;D2<30);(D3+H2);IF(AND(D2>=30;D2<60);(D3+H4)))
Now, this works fine when I only calculate the female data, but I can't seem the find the way to include the formula to choose from the MALE table, if the subject is male ("M").
Any help or clues on how to resolve this?
Welcome to stackoverflow. It would be easy to help you if you paste a screenshot of your table etc as it would make us understand your problem clearly.
Anyway, two solution advice from me:
1- you can use nested if operators but not like yours. Before expressing conditions with and operator, add another if to start processing data related to females. Like this: =IF(D1="F";IF(AND(D2>17;D2<30);(D3+H2);IF(AND(D2>=30;D2<60);(D3+H4))).
After processing females, add the same formula strings this time for males. This will solve your puzzle I guess.
2- my second advice would be creating a user-defined function. I often create a user-defined function if my formula gets too long and become hard to read. I strongly recommend you to search for this as it will make you better-understand the logics in excel functions and make you equipped against your puzzles in future.

Index Match Match across multiple columns

I have an Index Match Match question that I have not been able to find the answer for in researching. Although the solution may actually might be different than an Index Match Match formula - I'm open to try something more efficient than my current workaround.
I have one worksheet with data from my company on it. We sell a Product (let's call it Coke Zero) and we track the weeks that we put a promotion on and how much profit we make by selling it to the retailer. For example a promotion for Coke Zero starts the first week of Jan and ends 3 weeks later and we make a gross profit of $100 each week the promotion runs. I then have an external database with sales data formatted on a weekly basis to tell me how many units of Coke Zero I sold in each week. My internal data has thousands of lines like this with dozens of products, however the promotions are consolidated on one single row regardless of if it runs for more than one week, making matching up to the external database difficult. I need to create a lookup for what our Gross Profit was for each week of the promotion.
I have attached an example image of the workbook + two data sheets of what I've tried to do, summarised below.
On the Internal Data Sheet I've created additional columns to the right with all of the weeks listed that the promotion is on for, and concatenated them with the Product Code to be able to match week by week to the data in the External data sheet. Then my lookup basically checks every column one after another until it finds one where the concatenate of Week_Product Code concatenate matches.
My current solution technically works but my final formula is really slow and cumbersome given the data can be anywhere from 10K-200K lines when looking at multiple retailers. I was hoping to find a more efficient formula to complete the lookup.
Current solution on the External Data Sheet Column E:
=IF(ISNUMBER(MATCH(D2,'Internal Data'!$E:$E,0)),INDEX('Internal Data'!$D:$D,MATCH(D2,'Internal Data'!$E:$E,0)),
IF(ISNUMBER(MATCH(D2,'Internal Data'!$F:$F,0)),INDEX('Internal Data'!$D:$D,MATCH(D2,'Internal Data'!$F:$F,0)),
IF(ISNUMBER(MATCH(D2,'Internal Data'!$G:$G,0)),INDEX('Internal Data'!$D:$D,MATCH(D2,'Internal Data'!$G:$G,0)),
"0")))
I got SUMPRODUCT to work using this formula in J2:
=SUMPRODUCT(--($B$2:$D$3=H2)*--($E$2:$E$3=I2)*$F$2:$F$3)
And, you don't need those concatenated lookup columns:
Well, that was fun.

How Do I Nest IF Functions in Order to Calculate Daily Revenue?

I am working on a data set and I need to calculate the daily revenue of fake AirBnb listings using nested IF statements. This is for a bootcamp I am attending, and I am stuck.
My instructions are as follows:
Estimate revenue per listing
Assume each booking always has 2 guests, unless the listing accommodates only one;
The booking is always for the minimum number of days allowed;
Only half of the bookings generate a review;
The extra person charge is per night (column name ‘extra_people’)
○ Format: have a column that calculates daily revenue (account for number of guests accommodated, number of guests included in the price, extra charge for additional people - using nested IF statements); another column would then calculates revenue per booking; finally, multiply that by the number of total stays the listings has had.
Using the data in my dataset, I am attempting to fill out column AA. So far this is what I have for my formula,
However, I get an error. I know the first part of this formula would work for the scenario in row 4. However, I need to make sure that the formula takes into account scenarios where the "guests included" is less than the "accommodates", because I must assume that each booking always has two guests except for when the listing only accommodates one person.
How should this formula be written? Can I not create equations within nested if formulas if it includes adding, subtracting, dividing, or multiplying columns together?
To clarify the previous response a bit more, the structuring of IFstatements is important. Keep in mind the structure of the function: =IF(logical test, value if true, value if false). So, the second IF function (the first nested) needs to be placed where the first "value if false" comes in - each additional IF needs to be within the previous IF function. Using your example, the corrected form would be =IF(W4=Q4,V4,IF(W4<Q4,Q4*V4...)). I'm not sure what the "+X4" is supposed to be adding to, but this hopefully makes the structure clearer for you to work with. Good luck!

AverageIf and Multiple data strings

I'm involved with a youth football tournament on the referee side, with assessing/coaching the referees. I've just taken over doing the data entry for the referees assessment scores which we then use to determine who gets finals etc and am looking to extract more usable information from the data to help us identify trends.
I've got (up to) 200 referees, each receiving from none to two assessment scores each day for 5 days. The scores are entered as both the raw mark and the weighted mark based on match difficulty (along with a host of other data about the match that isn't relevant to this issue.
I can extract the average mark (raw and weighted) across all referees without issues and have done so using the below formula, which is the raw average mark:
=AVERAGE(Working!AK4:AK200,Working!BK4:BK200,Working!CL4:CL200,Working!DL4:DL200,Working!EM4:EM200,Working!FM4:FM200,Working!GN4:GN200,Working!HN4:HN200,Working!IO4:IO200,Working!JO4:JO200)
But I also want to extract the average mark (raw and weighted) across two subsets - Academy and non academy referees, to help plot trends and determine where resources need to be utilised.
I've attempted to use an AVERAGEIF formula, but am getting a #VALUE! return. This is the formula that I've attempted to use to return the average raw mark for those referees in the academy:
=AVERAGEIF(Working!G4:G200,Working!G4:G200="Yes",(Working!AK4:AK200,Working!BK4:BK200,Working!CL4:CL200,Working!DL4:DL200,Working!EM4:EM200,Working!FM4:FM200,Working!GN4:GN200,Working!HN4:HN200,Working!IO4:IO200,Working!JO4:JO200))
If I do the same formula as above, but without the brackets around the [average_range], I get a 'you've used too many arguments, and it highlights BK200.
From what I've been able to find so far online, it seems that the formula I'm trying to use would only work if ALL the cells in (Working!G4:G200) returned "Yes". However if there are only 50 academy referees as indicated by "Yes" in G column, then I want those specific scores to be averaged, and the inverse for the non-academy referees.
I thought about having another sheet, which would simply contain populate from Column G (a simple =G4 and then populated down to =G200 next to all of the scores), consolidated into a block of raw marks columned under Assessment 1, 2, 3, 4.... and then the same for all of the weighted marks which would populate from the equivalent cell on the working sheet, but there's a lot of filtering, and re-sorting that goes on on the working sheet, and I'm not 100% certain that that wouldn't cause issues.
Any feedback on how to work through this problem, so that I can display the overall average mark for academy and non-academy referees in both raw and weighted form would be much appreciated, and I apologize if this post is rather convoluted.
I don't think there is a neat solution if the scores are in several columns which are not consecutive.
My suggestion is:-
(1) Work out the sum for each column separately and total them up
(2) Work out the count for each column separately and total them up
(3) Divide Sum by Count to get Average.
In my small example below with 3 referees and 3 columns:-
(1) In K2:-
=SUMIF(H2:H4,"Yes",B2:B4)+SUMIF(H2:H4,"Yes",D2:D4)+SUMIF(H2:H4,"Yes",F2:F4)
(2) In K3:-
=COUNTIFS(B2:B4,">=0",H2:H4,"Yes")+COUNTIFS(D2:D4,">=0",H2:H4,"Yes")+COUNTIFS(F2:F4,">=0",H2:H4,"Yes")
(3) In K4:
=K2/K3
This would include any zero scores (if this is possible) but exclude any blanks.
You can then scale it up to your data.
Beyond this, you would have to change the data structure either
(1) Add a row to label the columns that you want to average e.g.
Score 1 Score 2 Score 3
3 0 3
so you could pick up only the columns labelled 3 say
Here's how it would be in my small example:-
In K3:-
=SUM((B$2:F$2=3)*($H3:$H5="Yes")*B3:F5)
Which is an array formula and must be entered with Ctrl-Shift-Enter
In K4:-
=SUM((B$2:F$2=3)*($H3:$H5="Yes")*(B3:F5<>""))
another array formula
In K5:-
=K3/K4
This is how the columns you want are labelled with a 3 in row 2, so it ignores the other columns:-
(2) Consolidate them into another sheet as you suggest.

Resources