How return substring of count for override for found december? - excel-formula

I have a spreadsheet that will always return varying row contents. So I need to search each row to find the january, february, march, april, may, june, july, etc content and extract the counts from that in the cell with substring. I'm not certain how to do this since the location in the row will always vary. Any ideas? I was thinking vlookup or index or match, or mid/search, but I'm not sure.
Example spreadsheet content, notice some rows have the overallCount and some have overrideCount, and a string like "overallCount 2022/12 35" is the complete cell value, where 2022 is the year, and 12 is the month:
result1 result2 result3 result4
overallCount 2023/01 11 overallCount 2022/12 35 overallCount 2022/01 12 overrideCount 2022/08 5
overallCount 2023/02 1 overallCount 2022/11 34 overrideCount 2022/02 9 overrideCount 2022/01 5
------ (3 rows) OverrideYearOrders overrideCount 2022/10 2 overallCount 2023/01 6
And the rows can have varying column numbers as well if there are more or less orders for each device.
I want to add a formula in result8 column or so, and search to the left of each row, and pull out the counts in columns for Jan, Feb, March, April, May, etc. I was thinking of something like this:
=VLOOKUP("overrideCount 2022/12",H6:AC8517,1,FALSE)
but it's not returning the count. It's returning #N/A
example per-row output on the right:
Overall Override
Jan2022 Feb March April May June July Aug Sept Oct Nov Dec Jan2023 Jan2022 Feb Mar ...
35 11 5
As you can see, not every month has a count that would be found in the row.
How would I pull those monthly counts for overall and override out to the right in each row?
Update*
This is the generated table per comment below:
result1
result2
result3
result4
result5
Output to right here Overall Jan2022
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Override Jan2023
Override Jan2022
Feb
overallCount 2023/01 11
overallCount 2022/12 35
overallCount 2022/01 12
overrideCount 2022/01 5
35
11
5
overallCount 2023/02 1
overallCount 2022/11 34
overrideCount 2022/02 9
overrideCount 2022/01 5
34
5
9
------
(3 rows)
OverrideYearOrders
overrideCount 2022/10 2
overallCount 2023/01 6
6
Example output is shown to right in generated table above, and also example per-row output is given in this before this added update already.

FORMULA:
This formula will get you to where you want pending a couple changes.
Rename the column headers to represent the date you want to calculate for (1/1/2022, 2/1/2022, ...).
This formula requires every cell value to "search" to be of "overallCount yyyy/mm" or "overrideCount yyyy/mm"
format
Drag and drop the formula for as far as you need it (row and columns).
First formula, totaling overallCount (F2:s2)
=IF(SUMPRODUCT(--IFERROR(SEARCH("overallCount "&TEXT(F$1,"yyyy/mm"),$A2:$E2)>0,FALSE)*SUMPRODUCT(--IFERROR(RIGHT($A2:$E2,LEN($A2:$E2)-(FIND("overallCount "&TEXT(F$1,"yyyy/mm"),$A2:$E2)+20)),0)))>0,SUMPRODUCT(--IFERROR(SEARCH("overallCount "&TEXT(F$1,"yyyy/mm"),$A2:$E2)>0,FALSE)*SUMPRODUCT(--IFERROR(RIGHT($A2:$E2,LEN($A2:$E2)-(FIND("overallCount "&TEXT(F$1,"yyyy/mm"),$A2:$E2)+20)),0))),"")
Second formula, totalling overrideCount (R2:AG2)
=IF(SUMPRODUCT(--IFERROR(SEARCH("overrideCount "&TEXT(T$1,"yyyy/mm"),$A2:$E2)>0,FALSE)*SUMPRODUCT(--IFERROR(RIGHT($A2:$E2,LEN($A2:$E2)-(FIND("overrideCount "&TEXT(T$1,"yyyy/mm"),$A2:$E2)+21)),0)))>0,SUMPRODUCT(--IFERROR(SEARCH("overrideCount "&TEXT(T$1,"yyyy/mm"),$A2:$E2)>0,FALSE)*SUMPRODUCT(--IFERROR(RIGHT($A2:$E2,LEN($A2:$E2)-(FIND("overrideCount "&TEXT(T$1,"yyyy/mm"),$A2:$E2)+21)),0))),"")
EXPLANATION:
The formula is using the SUMPRODUCT function which multiplies the corresponding elements of the arrays and returns the sum of products.
The formula uses the SEARCH function to look for the occurrence
of the string in the cells using the format
"yyyy/mm", in the cells of the range A2:E2 and returns TRUE if
found, otherwise returns FALSE.
The formula uses the IFERROR function to check for errors and returns
0 if error is found.
The formula uses the RIGHT function and is used to extract the rightmost
part of the cell, starting from the position of the found string -20/-21 (calculation that takes advantage of the date in the column header plus its position in order to autofill). In short, it totals the number after the date.
EXAMPLE:
The following formula is the root formula that is just wrapped in an IF THEN statement to show empty cells instead of 0's. This formula is written assuming Cells A1:E1 are the 'results' headers, and starting at Cell F1 is the date start of your dates. (Jan22-Feb23 of each category)
SUMPRODUCT(--IFERROR(SEARCH("overallCount "&TEXT(F$1,"yyyy/mm"),$A2:$E2)>0,FALSE)*SUMPRODUCT(--IFERROR(RIGHT($A2:$E2,LEN($A2:$E2)-(FIND("overallCount "&TEXT(F$1,"yyyy/mm"),$A2:$E2)+20)),0)))

Related

Excel: Calculation with different beginning dates

I have a long time-series of monthly returns for the S&P500. I would like to calculate the 3-month return, for a subset of dates?
For example, I would like to calculate the 3-month return for the following
A B C
Month Year 3-Month Return
Jan 1929
Dec 1948
July 1981
I have monthly return data like:
A B C
Month Year Monthly Return
Jan 1929 0.102
Feb 1929 0.072
Mar 1929 -0.231
....
....
Dec 2019 0.157
So the first calculation would be something like (1+0.102)(1+0.072)(1-0.231)-1. I can do this manually but have many calculations, unfortunately.
to find the match, you need a unique column, so combine A & B to another column, so that the month+year combination is unique, then use that combination to find the values.
Suppose you have data in this form:
The formula for match index is =match(P3,U$3:U$13,0) and that for your 3 monthly return is =(1+index(V$3:V$13,Q3))*(1+index(V$3:V$13,Q3+1))*(1+index(V$3:V$13,Q3+2))-1
You can put the match index inside the formula in C column to avoid the column, but you'd have to put it 3 times. you can also use different combination for combined date, like the actual date format of mm/yyyy, it'll still work.

count and sum function not properly working

I am working in excel and for some reason my sum or count function is not working properly. Or, perhaps I am not using the correct function or in the right way.
A B C D E F G H
February Max March Max
1 28
2
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
IF(SUM(E:E>0),31,"")
I have the above columns, I want the Max columns to show a specific number only if there is data in their respective month column. February has data, so it shows 28. March does not have any data so it shows no max. I need to look at the entire column or at least a large area (row 2 to row 2000).
The issue I am having is that if I do not have a value in the first row, but do have values in later rows, the sum or count function will to recognize that and will return zero.
A B
February Max
3
4
5
7
11
15
17
19
22
23
25
IF(SUM(A:A>0),28,"")
I have tried both sum and count functions, neither are giving me the results I want. I have also tried making >= 1. I found from StackExchange that someone was having a similar problem and a solution was to change the cell format to a number. That did not work either. Any suggestions?
Per my comment, you could use COUNTA() which checks if a cell is blank.
While it doesn't answer the technical reason SUM/COUNT isn't working, it should work for your intended purposes.
=IF(COUNTA(A:A)>0,28,"")

Excel formula to Count zeros only from Left to Right

I am currently using the following formula (i.e. =IF(A9<>"0";COUNTIF(A9:L9;"0");" ")) in a range "Jan to Dec" to get the number of zeros from left to right only and it is giving me 3 for 1st row, second & third rows as well. But what I want is, it should count zeros only from left to right (only in first and third cases). Only in second case it should not count zeros, because they are coming after some value, but it should count in 1st case and 3rd cases.
Can someone please help me with the formula?
Jan Feb Mar Apr May Jun Jul
0 0 0 5 10 15 20
10 15 20 25 0 0 0
50 0 0 0 30 35 40
Per comment conversation with OP vbalearner, assuming your data setup and desired results look something like this:
Then the formula in the cell and copied down is:
=IF(A9=0,IFERROR(MATCH(TRUE,INDEX(A9:L9>0,),0)-1,12),IF(B9=0,IFERROR(MATCH(TRUE,INDEX(B9:L9>0,),0)-1,12),0))
Shortened version:
=IF(OR(A9=0,B9=0),IFERROR(MATCH(TRUE,INDEX(IF(A9=0,A9:L9,B9:L9)>0,),0)-1,12),0)
With a helper row inserted at the top (may be hidden) with month numbers (1 for Jan etc) and assuming Jan is then in A2 please try:
=MIN(IF(A3:G3<>0;A$1:G$1))-1
entered with Ctrl+Shift+Enter and copied down to suit.

Excel - Lookup value in multiple columns

I have a datasheet with multiple columns that I want to search through - ending up with returning the top row value(s) in the found column(s). How to do this?
My idea would be to combine index with match, but I am rather lost for specific ideas...
January February March April May June
1 2 3 4 5 6
7 8 9 10 11 12
2 7 1 8 4 5
9 10 11 12 6 3
E.g. Search for: ID 3 - should return: March, June
Regards,
Nyborg
You need to add a VLOOKUP for each columns and after build the result
Following the Scheme:
A7 -> =IF(IFERROR(VLOOKUP($A$9;A1:A5;1;);"")="";"";A1) and autocomplete
D9 -> =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CONCATENATE(A7;",";B7;",";C7;",";D7;",";E7;",";F7);",,";",");",,";",");",,";",")
D10 -> =IF(RIGHT(D9;1)=",";LEFT(D9;LEN(D9)-1);D9)
Formula for D9 & D10 it's only to have a good display of the results.
UPDATE Version:
Considering you agree to have the Row 7 ... You can simplyfy using the Result formula:
=INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);1))&IFERROR(", " & INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);2));"")&IFERROR(", " & INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);3));"")
List it's the name Range of Row 7. The formula shall be apply with Ctrl+Shift+Enter.
This formula collect the first 3 value.
If you want more, add for each nth value you have:
&IFERROR(", " & INDEX(List;SMALL(IF(List<>"";COLUMN(List)-MIN(COLUMN(List))+1);3));"")
changing the last numer (in this case 3) and putting 4, 5, 6 ...
Obviusly if the result can be a lot, have few sense... Consider to use VBA !

Two Columns with Similar Data in Excel How to Match One Columnn and Return The New Data

I have columns in excel
ORDER NUMBER Order Paid Date Order Total Order Date
A1=1 B1= jan 1 c1= $1 d1= Dec 1
A2=2 B2=jan 2 c2= $1 d2= Dec 1
A3=3 B3=jan 3 c3= $1 d3= Dec 1
Then I have another column
ORDER NUMBER Shipment Date
I1=1 J1= Jan 5
I2=2 J2= jan 6
I3=3 J3= jan 7
How do math the order number (I1) to the order number in A1 and add it to the next column so it would look like this
ORDER NUMBER Order Paid Date Order Total Order Date Shipment Date
A1=1 B1= jan 1 c1= $1 d1= Dec 1 E1= JAN 5
A2=2 B2=jan 2 c2= $1 d2= Dec 1 E1= JAN 6
A3=3 B3=jan 3 c3= $1 d3= Dec 1 E1= JAN 7
I have tried Vlookup =VLOOKUP(A2,$J$1:$K$14075,2,FALSE) with the proper columns but that doesnt work, is there any other formula that would?
Thanks so much I greatly appreciate all the responses.
You say proper columns but the sample data you provided says you have them in columns I and J?
I would use the following formula:
=VLOOKUP(A2,$I:$J,2,FALSE)
$I:$J covers the two columns completely.
You have your Order date and shipment date data in columns I & J, but are running your VLOOKUP in J&K - try changing the range to $I$1:$J$14075 and see if that helps you.

Resources