Totals in excel without including certain cells - excel

This might be a bit difficult to explain, but below is the spreadsheet im using, for the totals highlighted in blue i want to create a formula that shows the difference between the two years but only up to the previous month. For example as we are currently in July, i want to show the difference in the two years from May-June.
Currently i am using the formula;
=SUM(K4:K5)-SUM(F4:F5)
Which works, but it means i will have to update it every time i add information in for the new months. Is there a formula i can use thats not overly complicated to get the same result, but it will update automatically when i add new information in.

You can use the =SUMIF() formula.
It will only perform the sum operation if certain conditions are met, so we can set it up to sum all entries in a certain range that are not empty.
Here is a good explanation of the function.
https://exceljet.net/formula/sum-if-not-blank
So for your case, you would write (in the sum cell)
=SUMIF(K4:K15,"<>",K4:K15) - SUMIF(K4:K15,"<>",F4:F15)

Related

Is there a way to count the value of a cell under the criteria in Excel?

I've been toying with this problem for some time but no matter how hard I try, I can't wrap my head around the syntax of a command.
Screenshot of Spreadsheet:
First thing's first. The layout of this spreadsheet can't be changed in any way, making this problem a whole lot more difficult to solve. I've added a screenshot above of what the spreadsheet looks like at the moment. It is currently just a test-sheet as the master-sheet is having real data inputted into it.
So the first problem is searching the array "D:H" for the shot listed in the "I" column. For example, I want to count how many times "Vodka" appears in the array (D:H).
The second problem is I then want to sum each number contained in the cell below the criteria. Following the same example, given the criteria "Vodka" (I4), I want to be able to sum all of the cells under any cell containing the word "Vodka".
The third problem is then to multiply it by the "Amount Sold". Once again, following the same example, I would multiply it by the cells "C5" and "C9" as both of the cocktails have a shot of vodka in them.
The last problem really wraps it all up in a tight little bow. All of this will need to be adaptable to adding, removing and changing cocktails to this list, as well as the shots that are in them and the shots that are being searched.
Again, this is all test information as I don't feel as though I should be putting out anything involving my workplace.
Any help on this would be greatly appreciated.
Count amount of vodka in D:H
=COUNTIF(D4:H13, "Vodka")
Sum of all Vodka
=SUMIF(D5:H5,"Vodka", D4:H4)
Instead of Hard-coding "Vodka" in the cell you should use reference to the cells. This makes expanding the table easier
If you have the value the last multiplication is no problem.

Excel VBA - customized SUMIF function [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have data like below. First column has combination of tags and numbers and second column has values
e.g.
First row: AB value is 10
Second row: Out of the value 20, AB is 10% & PQ is 90%
As these tags are custom defined for classification, the letter & numbers can be assumed to follow 2 characters each, except if the percentage is 100% there won't be any numbers after the letters (e.g. first row - AB)
If we segregate the tags and their values, it will be like below
I guess, an enhanced/customized SUMIF function is required to achieve this. Hope someone can give some ideas
What was tried so far:
I tried to do the steps in multiple steps, breaking down the tag into columns --> I was successful, but could not figure out how I can multiply the factor and get a summation. This way of doing it makes it hard to port the formula to other worksheets. Need to create additional columns etc. Hence abandon that plan
Thought of creating a VBA script to enhance the SUMIF function. Buy doing this I can copy the VBA code to other sheets and use my custom function. If needed the function can be enhanced further. To get some ideas on this plan, I posted this question
Thanks
I'm going to do this in two steps to make it easier to understand. First step: separate out the percentage factor by each keyword. Set up a table to the right of your data.
In the first row are all the codes you want to create sums for. Underneath it are the various desired percentages for each of your data rows. We're going to look for what's in row 1 inside what's in column A. If we don't find it then the element percentage is zero, if we find it but there's no number after, then the percentage is 100, otherwise use the 2 digit number that follows. Here's the formula in E2:
=IF(ISERROR(FIND(E$1,$A2)),0,IFERROR(VALUE(MID($A2,FIND(E$1,$A2)+LEN(E$1),2)),100))
The first part says if you don't find E$1 inside $A2 use a zero factor. The rest says to pick up the two digit number after the point you found E$1, but if it fails, use 100.
After copying the formula into all the cells, you can see the above factors. The rest is pretty easy. Incorporate the above formula into a sum range, multiplying by the value in column B and dividing by 100.
={SUM(IF(ISERROR(FIND(E$1,$A3:$A7)),0,IFERROR(VALUE(MID($A3:$A7,FIND(E$1,$A3:$A7)+LEN(E$1),2)),100))*$B3:$B7/100)}
Don't forget to terminate this array formula with Ctrl-Shift-Enter. I got the following results:

How do I sum several rows by category? (EXCEL)

I have created an excel sheet to have an overview over costs in my projects, however, I also need an overview of costs per category in my projects. I googled it and tried to find examples online, however, it only returns a value of 0, which shouldn't be the case. Can anyone help me? The sheet looks like below.
I am going by the SUMIF function to group by category but my excel sheet is a bit more complex than that so I tried to adjust it accordingly as seen in the code below. No matter what I do it either returns an error or 0.
=IF(B12=B8;"";SUMIF(B12:B39;B12;J12:BE39))
In the formula above I am trying to sum the costs of a category that could be written in B12, for example, Software development. For confidential reasons, I cannot show the actual filled out excel sheet.
sumif does not work with summing multiple columns. Instead use a sumproduct statement instead like so:
=IF($B12=$B$8;"";SUMPRODUCT(($B$12:$B$39=$B12)*($J$12:$BE$39)))
A detailed explanation to how this works can be found here
Edit:
I sense a follow up question coming, how to skip certain columns. Because as you have set it up now, it will count the entire range from J12 to BE39, in which you have both forecast costs and actual costs. I guess this is to compare the costs to what was projected and what the actual costs are. Right now it will count both the projected and actual cost, doubling up. To prevent this you can enter every second column separated by a + like so:
=IF($B12=$B$8;"";SUMPRODUCT(($B$12:$B$39=$B12)*($J$12:$J$39+$L$12:$L$39+$N$12:$N$39)))
Also I have added $ signs to all non-changing values so it will work when dragging down the fill handle on the formula to populate the below cells.

Excel SUM COUNTIFS from different tables and futureproofing

I'm practising MS Excel skills. I have a workbook in which I want to analyses data from different tables.
Each worksheet contains a table with the information from the year. So in worksheet "2017" I have a table named "Table2017". I have this for each year (starting 2015).
After a some research, I finally found a way to count how many times something in a certain place happened.
=SUM(COUNTIFS(Table2018[Place];B3;Table2018[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2017[Place];B3;Table2017[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2016[Place];B3;Table2016[Activity];{"Paid";"Awarded"}))
+SUM(COUNTIFS(Table2015[Place];B3;Table2015[Activity];{"Paid";"Awarded"}))
This works perfectly. It will calculate how many times per place a paid service or an awarded (gifted/sponsored) service was delivered. In the B column, I have a list of places (hence the B3 reference), so after completing the formula, I can select the cell and enlarge/drag to copy it to the rest of the column and apply for every place.
However, the formula is really long and every year upon creating a new worksheet, I need to add a new part to the formula.
Is there a way to compact this? And ideally have the formula search for every table that has the relevant information (like: "Table20??" or "Table 20*"), go in and count the times my conditions are found?
I hope my question is clear enough.
Thanks in advance!
P.S. I have zero experience in VBA/VBS, so I'm hoping to realize this in a normal formula.
There are ways to make it more compact, but they will necessarily make the function more complicated, so it wont be any easy win. See for yourself:
you basically need to be able to cycle through the years inside formula without creating custom formulas. One way to do this is to use ROW inside INDIRECT function. This way you can replace multiple
Table2015[Place]
with one array function containing
INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]")
as it is an array function it will essentially cycle through the cells in the ROW function creating Table2015[Place], Table2016[Place], Table2017[Place] and Table2018[Place]. Your whole formula would look something like this
=SUM(COUNTIFS(INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Place]");B3;INDIRECT("Table"&ROW($A$2015:$A$2018)&"[Activity]");{"Paid";"Awarded"}))
and it must be entered using ctrl+shift+enter (you will see {} brackets around the function). This should work to make the function smaller and you will need only to change the cell reference each year instead of adding another sum, but the question is if the separate sums are not easier to read and maintain.

Excel 2013 advanced date range lookup using sumproduct

I am new to Stackoverflow, so please let me know me if there is not enough information. I have had many helpfull insights by using StackOverflow in the past, but I cannot find any helpful thread online, so I hope you can help me.
I've been working on a excel (2013) problem for a while now. I am trying to build a marketing agenda to store and keep track of our mailing campaigns. The campaigns themselves are send via another system, but we miss the ability to plan our mailing campaigns in advance. Since we are active on different markets in Europe, we decided to have a general mailing (for all regions) and a region specific mailing campaign (both are in the same agenda). Besides this we also want to display the mailing focus (different brands). It is my idea to return this as visual as possible (to make it usable for all users). I have add a small picture to show my desired end-result (however without any data at this moment).
At this moment, the users are going to use a (Google)form to enter the campaign information and this data is downloaded to the worksheet (by doing so all users can add new campaigns and everyone always has access to the most recent data). This part works well.
I am using a helper sheet to check if the dates fall in a campaign range, if it does fall in a campaign range it should return the mailing ID (also the row number). I have another form which uses this data to search for the right brand and displays visually (with a lot of conditional formatting).
The problem arises in the helper sheet (when I check if a date fall into a campaign range). I have been able to get it working (more or less) with the following formula:
=IF(SUMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper!$D$2:$D$100>=$B4);RIJ(CountryHelper!$C$2:$C$100))=0;"";INDEX(CountryHelper!$A$2:$A$100;SOMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100))))
In this formula, CountryHelper!C:C is referencing the StartDate of the mailing campaing. D:D will reference the column of the EndDates and A:A has the mailing ID. Cell B4 is the date that needs to be checked.
At first it looked this worked perfectly. If a date fell in a date range then it would return the ID. After a little playing around with this a problem came to light. It only works with non overlapping dates, once dates overlap excel will add the row numbers together and it would not work any more.
Is it possible to get the sumproduct formula working and returning only the first ID. I am aware that I then have to make another 2 formulas which return the second and third ID ( I am certain we do not get more than 3 overlapping dates). This is also the part where I get lost. I've tried to use a MIN and MAX variation wit the following sumproduct formula:
=SUMPRODUCT(--(CountryHelper!$C$2:$C$100<=$B4);--(CountryHelper_RSEU!$D$1:$D$100>=$B4);ROW(CountryHelper!$C$1:$C$100))
This will return either a 0 (with MIN) or 100 (With MAX). I think this is caused by the formula (for now it only searches the first 99 rows). I also have ventured into VBA / UDF to get this done, but as I understand it this is not possible.
Anyway, I am sorry for the long story, I hope that my problem is clear and you can help me. If you need any more information.
Thank you!
empty Marketing Agenda overview
The SUMPRODUCT is a kind of swiss army knife Excel function. But here it is wrong because, as you already have seen, it really calculates a SUM at the end. Mostly it works because it first multiplies the 0 or 1 of the conditions with the row numbers so only the row numbers which fulfills the conditions comes into the sum. But if two or more row numbers fulfil the conditions then they were added together.
Are you familiar with array formulas? The following array formula should be what you want:
{=INDEX(CountryHelper!$A$2:$A$100;MIN(IF((CountryHelper!$C$2:$C$100<=$B4)*(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100)-1)))}
To create a array formula put the formula into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter]. Then the curly brackets should appear automaticaly.
How it works:
{IF((CountryHelper!$C$2:$C$100<=$B4)*(CountryHelper!$D$2:$D$100>=$B4);ROW(CountryHelper!$A$2:$A$100)-1)}
Gets a array of row numbers or FALSE {FALSE, rowNumber, FALSE, ...}. If both conditions are fulfilled then it gets the row number - 1, if not then it gets FALSE.
The MIN function then gets the smallest (row number - 1) from this array.
The INDEX then indicates this smallest (row number - 1) which fulfills the conditions.
It subtracts 1 from the row number because your INDEX range starts at row 2. If the row number 2 fulfills the conditions then it is the index 1 within this range, if row number 3 fulfills the conditions, it is the index 2 and so on.
Why it only works as array formula? Because the IF function do not creates a array by default even if their "Value_if_true" is a range. Within the array context it does exact this.

Resources