Set mileage destination displaying - excel

I have some experience with excel but its very limited. I have a list of regular To & From destinations setup as historical data along with the mileage between.
What I have is basically cell A1 WIGAN + cell B1 LUTTERWORTH in Sheet 2 and I want a formula to match both of these from Sheet 1 and display the mileage. If the journey has no history then to display a NIL value.
It sounds simple but as yet I've not located anything that works or been able to work it out myself.

Try this:
=INDEX('Sheet1'!C:C,MATCH("NEWHOUSE",IF('Sheet1'!A:A = "WIGAN",'Sheet1'!B:B),0))
It is an array formula and must be confirmed with Ctrl-Shift-Enter.
Change the Column references to the actual reference; change C:C to $C$2:$C$1000. It will speed it up.

You could minimize the cross-reference table of mileage values by adding a reversed lookup if the first fails.
    
In Sheet5!C2 as,
=INDEX(Mileage!C:C, IFERROR(AGGREGATE(15, 6, ROW($1:$99)/((Mileage!$A$1:$A$99=A2)*(Mileage!$B$1:$B$99=B2)), 1), AGGREGATE(15, 6, ROW($1:$99)/((Mileage!$A$1:$A$99=B2)*(Mileage!$B$1:$B$99=A2)), 1)))

Related

Excel - How to get the corresponding quantity?

I have 1 workbook with 2 worksheets.
The first screenshot shows Worksheet A, the second screenshot shows Worksheet B
I would like to match the corresponding quantity to the corresponding grade in Worksheet A based on the Columns "Line", "Sub-Line", "Category", "Occasion", "Sub-Cat" and "Grade" in Worksheet B.
Question: How to get the corresponding quantity?
Many thanks!
Since you already have a concatenation of the search criteria in SheetB!F:F you might use this formula if you have Excel 365 (much earlier versions won't have the TEXTJOIN function).
=VLOOKUP(J2, SheetB!$F$2:$K$1000, MATCH(I2,SheetB!$F$1:$K$1, 0), FALSE)
Witness that the MATCH function includes F1, which must not have any of the captions found in G1:K1. $K$1000 is an arbitrary row number intended to be larger than anything you need. For use in my own project, I would create a dynamic named range instead of SheetB!$F$2:$K$1000.
This is a little heavy and perhaps someone can make an easier approach, but let's give it a go. NB: This requires Excel 2019 or 365.
You can put this into your QTY column in WORKSHEET A:
=SUM(TRANSPOSE(MMULT(SIGN(SEQUENCE(1,5)),TRANSPOSE(--(B5:F5=WorksheetB!$A$3:$E$14)))=5)*INDEX(WorksheetB!$G$3:$K$14,,MATCH(G5,WorksheetB!$G$2:$K$2,0))
That's hard to read, so here it is again with formatting (it works with formatting all the same):
=SUM( TRANSPOSE( MMULT( SIGN( SEQUENCE( 1, 5) ),
TRANSPOSE(--(B5:F5=WorksheetB!$A$3:$E$14) ) ) = 5 )
* INDEX( WorksheetB!$G$3:$K$14,,MATCH( G5, WorksheetB!$G$2:$K$2,0) ) )
Seems there would be an easier way, but it does not come to me at the moment.
As a side note - what you are doing looks very much like something that could be done in Power Query. It would make quick work of doing such match-ups and aggregations and if there is a lot more that you want to do with these data, it would support that as well.
You can use INDEX and MATCH for this:
=INDEX('Worksheet B'!$G$4:$K$26,MATCH(1,($B5='Worksheet B'!$A$4:$A$26)*($C5='Worksheet B'!$B$4:$B$26)*($E5='Worksheet B'!$C$4:$C$26)*($D5='Worksheet B'!$D$4:$D$26)*($F5='Worksheet B'!$E$4:$E$26),0),MATCH($I5,'Worksheet B'!$G$3:$K$3,0))
The formula needs to be entered with ctrl+shift+enter as it's an array formula.
It indexes the quantities in 'Worksheet B'!$G$4:$K$2 and returns the row number of where the value in Worksheet A of the line, sub-line, occasion, category, sub-cat matches the value in the resembling column in Worksheet B and the indexed column number of where the grade value in Worksheet A equals the header in Worksheet B'!$G$3:$K$3.
This worked for me!
=VLOOKUP(CONCAT(B10,"-",C10,"-",E10,"-",F10,"-",D10),'Worksheet2'!$F$4:$K$26,MATCH('Worksheet1'!M10,'Worksheet2'!$F$3:$K$3,0),FALSE)
Cheers

Ignore Duplicates and Create New List of Unique Values in Excel with offset

My question is related to a question asked earlier, but as I am a new member I was not able to comment on that question.
The earlier question asked how we can dedupe a list in a workbook to create a new list of unique values on another sheet in the same workbook. The top voted solution given by #achaudhr works for me but in that I need to specify the exact cells the formula needs to reference. In the comments on that answer #Dan has mentioned that we must use OFFSET if we are referring to a dynamic range.
This is the formula I am using at the moment:
B2=INDEX($A$2:$A$20, MATCH(0, COUNTIF($B$1:B1, $A$2:$A$20), 0))
I have tried using offset with this formula but I guess I am doing something wrong because it keeps giving me #N/A as a result.
If my data was in column A (as per the above formula), I want to be able to change the ":$A$20" part of the range dynamically. The list in column A changes as per an input I put in the workbook on another sheet (let's call it Sheet 3). Hence I cannot hardcode the cells in the index formula range or else I have to change this range every time my list updates.
Based on the above layout, the cell in E2 calculates the max cell number for the list in column A on sheet 1. This number changes when the input in Sheet 3 changes.
I edited the above formula to use OFFSET to reference E2 in the following way:
B2=INDEX(OFFSET('Sheet 1'!$A$1,'Sheet 1'!$E$2,0), MATCH(0, COUNTIF($B$1:B1, OFFSET('Sheet 1'!$A$1,'Sheet 1'!$E$2,0)), 0))
This formula is returning #N/A (and I did press Ctrl + Shift + Enter so its not because of that).
I hope the group here can help me solve this. Look forward to the inputs and thanks for all your help.
Thanks,
Neha
The way to use OFFSET in a dynamic range determining formula, where it is column length that varies, is to use that value as the [height] parameter.
So, in the case of your example, the formula would look like:
B2: =IFERROR(INDEX(OFFSET($A$1,1,0,$E$2-1), MATCH(0, COUNTIF($B$1:B1, OFFSET($A$1,1,0,$E$2-1)), 0)),"")
Reference: $A$1 (could also set this at $A$2 with a 0 Row offset
Row Offset: 1 (since A1 contains the header)
Column Offset: 0
[height]: Contents of $E$2 minus 1 (since we are not including the header in the list)
[width]: left blank

Extracting unique values from a range, but repeating each value x times before next unique value

I have a bit of a strange scenario. I am attempting to create a formula that, as the title suggests, that is supposed to extra unique values from a range (without blanks) but repeat them a set number (let's say 5) of times before returning the next unique value. For example, this is the A1:A6 (should be top to down but for the sake of space, I formatted like this):
1,2,2,3,3,3
What I want is a formula to drag them down to this on Column B.
1,1,1,1,1,2,2,2,2,2,3,3,3,3,3
As reference, the formula I'm currently using to return the unique values to repeat once, without blanks, is this:
=INDEX(A1:A6, MATCH(0, IF(ISBLANK(A1:A6), 1, COUNTIF(B$1:$B1, A1:A6)), 0))
Any suggestions? Many thanks in advance!
Put this in B2 and copy down:
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$1:$A$6)/((COUNTIF($B$1:B1,$A$1:$A$6)<5)*($A$1:$A$6<>"")),1)),"")

Excel - Check if value X and value Y is on the same row

I have an excel document with two sheets, data and edu-plan. The sheet data has the following information:
The sheet edu-plan looks like this:
My question is: how do i create an excel formula that checks if the target group on the specific row in edu-plan! has the course name in question on the same row as the target group in sheet data!, i.e. if Sales and Sales course is on the same row in the sheet data!?
In reality, the data sheet as a couple of hundred rows and will change over time, so i am trying to develop a formula that i can apply easily on all rows/columns in edu-plan!.
The desired result in edu-plan would look like this:
A pivot table might be a good way to go.
If you would like to do it by formula, then you can just use a COUNTIFS
=IF(COUNTIFS(data!$A$2:$A$10,$A2,data!$B$2:$B$10,B$1),"X","")
A possible way to solve your issue with an array formula:
Write in B2 of sheet edu-plan
{=IFERROR(IF(MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)>0,"x",""),"")}
Since it is an array formula, you need to hit shift + ctr + enter.
Here is the formula broken down:
MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)
checks whether the combination of row header and column header is in the data table. MATCH returns the index of the found combination. Since we are not interested in the location, we only ask IF(MATCH > 0, "x", "") to write an "x" if a match was found. If MATCH finds nothing, it returns an error, which is why we add an IFERROR(VALUE, "") around the construct.

Can we nest an IF inside a COUNTIFS in Excel?

I have been working on an attendance sheet and trying to make the monthly reports automatic. I have asked my previous question on the same issue and got the idea to accomplish the task.
But now I have stuck at one place. I have this below formula:
=COUNTIFS(C5:C27,">0", E5:E27,"G", F5:F27,"CAT1")
The value in cell "C" in the above is coming from the below formula (in cell "C")
=IF((COUNTIF(G5:AK5,"p"))>0,1,0)
I had to add this extra column ("C") only to supply input to my fist formula. My question is - "Can we merge the IF function inside the COUNTIFS to get the result in one go and to eliminate the use of an extra column (column C)"?
To perform these cell reference acrobatics you will likely need to switch to an array formula. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. A 'helper' column such as you've used in column C can generally reduce calculation cycles and make a worksheet more 'user friendly'.
A COUNTIFS function requires that the ranges being examined are not only the same size but also the same shape. Looking at G5:AK5 is not the same as looking at E5:E35 even though they contain the same number of cells¹.
In the sample data below, you formula is in A1 and uses the 'helper column' C. My array formula is in A2 and does not consider column C ahough it incorporated the logic.
        
The array formula in A2 is:
=SUM(IF(E5:E27 = "G", IF(F5:F27 = "CAT1", SIGN(COUNTIFS(OFFSET($G$5, ROW($1:$23)-1, 1, 1, 31), $I2)))))
Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula.
¹Some functions not only accept but welcome cell ranges that are the same number of calls but transposed. Offsetting or staggering the ranges is also an option if the cell ranges are the same size. In difficult cases the TRANSPOSE function can be helpful.

Resources