Excel- Sum groups of similar cell contents using wildcards - excel

I am trying to sum the amounts in column B based on the types of symbols in column A. Any symbol with "EW" at the start needs to be grouped and by date month - see column D. The second symbol comes in two formats but also needs to be grouped, so "OES" and "OMSX" needs to be grouped together and with their date month. I know I need wildcards here but I cannot get this to work.
EDIT, correct EW, accidentally had "EWS" before, apologies to anyone who responded

Thius should work if you can get your data corrected.
=SUMIFS(B:B, A:A, REPLACE(D2, FIND(" ", D2), LEN(D2), "*"), A:A, REPLACE(D2, 1, FIND(" ", D2), "*")&"*")

Related

Can you define names for dates in Excel to use them in formulas?

I hope you are all well.
I have a question. I have a list with many payments listed on column A with dates (format day/month/year) in column B and I would like to use a formula which says something like
IF= A1 = Q2, "pay", "don't pay" , IF= A2 = Q2, "pay", "don't pay"...
Q2 means quarter 2
Could I define names for dates? For example Q2 would be 01/04/2021 - 30/06/2021 so all the dates within that range would be named Q2.
Best regards
You may try anyone of the approaches as explained below, the first one is using ROUNDUP & MONTH Function and the other one is using DEFINED NAMES.
First Approach ---> Using ROUNDUP & MONTH FUNCTION
• Formula used in cell B3
="Q"&ROUNDUP(MONTH(A3)/3,0)
• Formula used in cell C3
=IF("Q"&ROUNDUP(MONTH(A3)/3,0)="Q2","Pay","Don't Pay")
So you can see i have used two columns in the first approach just to make it understandable, therefore just wrap the formula in cell B3 within an IF logic as shown in cell C3 to get the desired output.
Second Approach --> Using DEFINED NAMES & SUMPRODUCT FUNCTION
• Formula used in Defined Names
=ROW(INDIRECT(--TEXT("01-04-2021","dd/mm/yyyy")&":"&--TEXT("30-06-2021","dd/mm/yyyy")))
So you can see I have Defined the Quarter 2 as _Q2 and the reason is a name must either begin with a letter, underscore (_), or backslash (). If a name begins with anything else, Excel will throws an error.
Therefore the formula used in cell D3
=SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))
The above formula creates an array of TRUE's & FALSE's and multiplies to return the corresponding values.
Now the above formula when wrapped within an IF Function it gives us the requisite output as desired,
Formula used in cell E3 (Same it can be done in one cell, to make it understandable i have used two columns)
=IF(SUMPRODUCT((A3>=_Q2)*(A3<=_Q2))=1,"Pay","Don't Pay")
So this is how you can used a Defined names for dates in excel and then use the same within a formula.
This solution does not provide names for dates but it might meet your needs:
Make sure column A is formatted as a date, then use this formula to get the quarter from the month (this array allows you to set Q1 if it is not the same as calendar quarters):
="Q"&CHOOSE(MONTH(A1),1,1,1,2,2,2,3,3,3,4,4,4)
Then test the value of this column:
=if(C1="Q1", "Pay", "Do not Pay")
You could also create a cell at the top of your spreadsheet and name it current_quarter. Then you would type in the current quarter "Q1", "Q2", ... and your formula would be
=if(C1= current_quarter, "Pay", "Do Not Pay")
You are using standard calendar month quarters, so we can get the quarter number easily by dividing and rounding up.
=ROUNDUP(MONTH(A1)/3,0)
You can then use this number in your IF function.
=IF(ROUNDUP(MONTH(A1)/3,0)=2,"Pay","Don't Pay")

How to average an entire column but ignoring the header

I feel like this should be simple and my notation is just wrong, I know if i want to sum the entire column I can use this formula:
=AVERAGEIF(C:C, "<> ")
(I'm using "<>" as i need to ignore blanks)
How do i offset it by one row? I want it to start at C2 bu excel doesn't like
=AVERAGEIF(C2:C, "<> ")
Many thanks!
AVERAGE ignores text and blanks so,
=average(c:c)
... should be the same as,
=averageif(c2:index(c:c, match(1e99, c:c)), "<>")
(unless the header in C1 is numeric)

Calculations for every unique/distinct values

I have a very large data set that I need to work with and in my calculations three columns are of interest. Let's call the different columns [A], [B] and [C]. In [A] I have a list of different company names, where each company name might occur several times. I have created a table for the data and sorted the company names alphabetically. Let's say I have the company name X in A2:A5 and the calculation that needs to be done is SUMPRODUCT(B2:B5;C2:C5)/SUM(C2:C5). How do I calculate this for every unique/distinct company name and present the result in a nice way?
Use the following formula in a new column D for example in D2:
=IF(A2<>A1,SUMPRODUCT(--($A$2:$A$10=A2)*$B$2:$B$10*$C$2:$C$10)/SUMIF($A$2:$A$10,A2,$C$2:$C$10),"")
and drag it down whenever the value in A changes it will write a result
Change A2:A10, B2:B10 and C2:C10 to correspond your last row and keep $ for fixed references
To correspond to your settings I wrote ";" in the following:
=IF(A2<>A1;SUMPRODUCT(--($A$2:$A$10=A2)*$B$2:$B$10*$C$2:$C$10)/SUMIF($A$2:$A$10;A2;$C$2:$C$10);"")
Put two INDEX functions together with a : for the range.
=IF(A2<>A3, SUMPRODUCT(INDEX(B:B, MATCH(A2, A:A, 0)):INDEX(B:B, MATCH(A2&"z", A:A)), INDEX(C:C, MATCH(A2, A:A, 0)):INDEX(C:C, MATCH(A2&"z", A:A)))/SUMIFS(C:C, A:A, A2), TEXT(,))
The first occurrence is found with,
INDEX(B:B, MATCH(A2, A:A, 0))
The last occurrence (on sorted data) is found with,
INDEX(B:B, MATCH(A2&"z", A:A))
Note that I changed your SUM to a SUMIFS to make life a little easier.

Nicer solution for how to combine cells between two values in a second column

Even though I came up with a solution for my problem, I was hoping someone might help find me a new one that is not so "cumbersome"
Here is my situation:
a cell in column A either contains a value (time stamp) or is blank
the number of blank cells between each time stamp varies
a cell in column B always contains a value (string)
Here is what I need:
in column C, combine the strings in column B between time stamps in column A
Since I know that the maximum number of blanks in Column A between two time stamps is 5, I created this function..(I deleted the space between "" and inserted a line break in front of every IF for display reasons)
=IF(AND(ISNUMBER(A1),A2="",A3="",A4="",A5=""),B1&""&B2&""&B3&""&B4&""&B5,
IF(AND(ISNUMBER(A1),A2="",A3="",A4=""),B1&""&B2&""&B3&""&B4,
IF(AND(ISNUMBER(A1),A2="",A3=""),B1&""&B2&""&B3,
IF(AND(ISNUMBER(A1),A2=""),B1&""&B2,
IF(ISNUMBER(A1),B1,"")))))
If the maximum number of blanks would be 10, the formula would get extremely long...so any ideas how to come to the same solutions in a more elegant way are appreciated!
Thanks,
Ivana
If you're able to add some columns, you could simplify your formula.
I would add three new columns instead of just one. My solution assumes that you have a header at the top in row 1. It also allows for more than five blanks between timestamps, if that ever arises.
In row 2, enter the following formulas:
Column C: =IF(ISNUMBER(A2),B2,C1 & " " & B2)
Column D: =IF(ISNUMBER(A2),A2,D1)
Column E: =IF(D2<>D3,C2,"")
Paste or drag these down to the end of your timestamps and strings to fill in the columns.
Columns D and E will contain your timestamp and concatenated B string(s). You can either pick them off or filter them to get the non-blank strings.
EDIT FOR DUPLICATE TIMESTAMPS
If duplicates can occur and you need to track them separately, then change column E in row 2 as follows:
Column E: =IF(ISNUMBER(A3),C2,IF(ISBLANK(B3),C2,""))
Copy down as before.
You can apply some old INDEX function range addressing together with the newer TEXTJOIN function¹.
  
In C2 as,
=IF(A2<>TEXT(,), IFERROR(TEXTJOIN(CHAR(44), TRUE, B2:INDEX(B:B, MATCH(1E+99, A$1:A1))), TEXT(,)), TEXT(,))
Fill down as necessary.
¹ TEXTJOIN function became available with Excel 2016 with Office 365 and Excel Online.

SUMIFS within a date range

I am working on a excel file for my monthly budget. I am exporting my monthly transactions into a CSV file and then copying it over.
I have a tab for each month and all my categorizes that I am budgeting for. I then copy over the csv file to a tab called transactions in my budget workbook. Then I have a drop down list with all the categorizes from my monthly categories. Once I have categorized all my transactions that will total up on the corresponding budget sheet.
The issue I am having a hard time with is how do I create a specific equation that will recognize the month and then the specific category item. For an example "His - Income" I can easily use a sumif to get that information from a list, but how do I now separate further it for April only.
The data is organized on a tab by Date in column "A", description in column "B", and amount in "D". I am looking for an equation that will find "His - income" for 4/1/2015 to 4/30/2015.
You want to use a SUMIFS
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2,criteria2])
With one IF for the category, and two more for the date range. I will look something like this:
=SUMIFS(D1:D50, B1:50,"=His - income",A1:A50,">=4/1/2015",A1:A50,"<=4/1/2015")
I would change all the hard coded ranges (e.g. D1:D50 to named ranges) as well as the dates. If you put the dates in a cell it will change the formula to something like this: BudgetDates,"<="&F$1 (notice the ampersand)
The SUMIFS function can use operators other than equals; equals is just the default. With 01-Apr-2015 in J1 (sometimes 04/01/2015 formatted a mmmm) and His - Income in K1, you could use one of the following.
=sumifs(D:D, B:B, K1, A:A, ">="&J1, A:A, "<"&edate(J1, 1))
=sumifs(D:D, B:B, K1, A:A, ">="&date(2015, 4, 1), A:A, "<"&date(2015, 5, 1))
=sumifs(D:D, B:B, "His - Income", A:A, ">=4/1/2015", A:A, "<5/1/2015")
Unless you want to use it as a visual reminder, the = for exact martch is unnecessary. Typically, the upper limit of the date range is less than one day higher in case the dates contain times as well. The EDATE function will raise or lower a date by a number of months the equal to the integer in its months parameter.
For all intents and purposes, there is no adverse effect when using full column references with SUMIFS.

Resources