Get Sum Of Columns Values Filtered Based On Another Columns Date - excel

I have a spreadsheet that basicly have several hundred rows that look like this
|01-Jan-16 (Fri) | Work | 0 | 0 | 3 | 0 | 9 | 7 | 0 | 0 |
I have been trying to generate a query that will calculate the total of each of the columns during any given quarter. So it will essentially select all the dates for month 1-3, 4-6, 7-9, 10-12 and calculates the total of value in all the 8 columns.
I have tried sumsif, and sumproduct but I can't get it to work, I am currently playing around with
=SUMPRODUCT( (MONTH('2016'!$A4:$A999)=1) * (MONTH('2016'!$A4:$A999)=2) * (MONTH('2016'!$A4:$A999)=3) * ('2016'!$C4:$C999) )
=SUMIFS('2016'!C4:C999, '2016'!A4:A999, "<=3", '2016'!A4:A999, ">=1")
=SUMPRODUCT((MONTH('2016'!$A4:$A999)>=1)*(MONTH('2016'!$A4:$A999)<=3)*('2016'!B4:B999))

This worked for me.
=SUMPRODUCT( (MONTH('2016'!$A4:$A999)=1) * (MONTH('2016'!$A4:$A999)=2) * (MONTH('2016'!$A4:$A999)=3) * ('2016'!$C4:$C999) )

The date field is not a date value but a string so that is what is causing the problem. To get it to work you will need to pull out the date value for the match. I tested this with data created based off your example and it worked.
=SUMPRODUCT((MONTH(DATEVALUE(MID(A2:A5,1,9)))<=3)*(C2:J5))

Related

Pivot Table considers duplicate elements for the average calculation

I have a pivot table (with Data Model) based on below table
Id | Time
1 | 10
1 | 10
1 | 10
2 | 2
3 | 5
3 | 5
4 | 4
5 | 8
I need to calculate the average of time.
Average based on the pivot table calculation is 6.75 --> (10*3+2+5*2+4+8)/8
However, my expected result is 5.8 --> (10+2+5+4+8)/5
How can I setup the pivot table to not take into consideration the duplicate ?
Please note that I can't remove duplicate rows.
I tried to use AVERAGEX : =AVERAGEX(VALUES('Range'[Id]);'Range'[Time]) with DAX.
But I'm facing this issue: This formula is invalid or incomplete: 'Calculation error in measure 'Range'[475e7fe7-92b4-478c-bd5f-6e7c95df27d7]: A single value for column 'Time' in table 'Range' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.'.
Thank you in advance !
Solution
=AVERAGEX(VALUES('Range'[Id]);CALCULATE(AVERAGE('Range'[Time])))
Solution
=AVERAGEX(VALUES('Range'[Id]);CALCULATE(AVERAGE('Range'[Time])))

Excel - Rather complex SUM IF criteria

I have roughly the following setup:
Values:
MONTH | DURATION | VALUE |
5 | 3 | 120 |
6 | 1 | 100 |
Expected outcome for totals:
MONTH | TOTAL
5 | 120
6 | 220
7 | 120
What I would like to do, is to be able to sum in another table the total values for each month. The logic would be to SUM every value where the total table's month is equal or higher than that of the values, but lower than the value's month + duration.
Does that make any sense? Is that possible? I'm cracking my head and I can't seem to find a way to solve it.
Thank you very much.
The easiest solution is probably to make another column with the end month. And then use SUMIFS to check if month is >= starting month and <= ending month.
=SUMIFS(<Range of Values>,<Range of starting>,"<="& "Target month",<Range of ending>,">="& <Target month>)
DSUM is the best candidate for this, I believe. See Microsft's documentation and this site for help understanding function, and what it is doing. I have made very complex calculations possible in Excel by using the "database" methods (DSUM, DCOUNT, etc).

Excel: Average of parts of a column based on another column

Using Excel 2011 for mac, I have three columns: ID, Start date, end date and time to completion. (Date format: dd/mm/yyyy)
ID | Start | End | Time
1 | 01/01/2016 | 05/01/2016 | 4
2 | 04/01/2016 | 08/01/2016 | 4
3 | 01/02/2016 | 14/02/2016 | 13
4 | 02/02/2016 | 20/02/2016 | 18
5 | 01/03/2016 | 05/03/2016 | 4
6 | 06/03/2016 | 08/03/2016 | 2
7 | 12/03/2016 | 15/03/2016 | 3
Column D is basically the difference between column C and column B.
Now I have the total average, which is easy to calculate but I'd also like to have the averages for the different months.
And this is where my knowledge falls apart. I've tried several things but I can't seem to figure out how to calculate an average using only the cells in a column that match a certain value in another column. I could sort the tickets by date and do it manually by doing the average for only a certain range but as this list constantly changes this is definitely not a nice option.
Check out the AVERAGEIF function
AVERAGEIF(selection_range, criteria, averaging_range)
It uses the values in the selection_range to filter which values in the averaging_range will be averaged.
In your case you could say AVERAGEIF(B1:B8, "01/01/2016", D1:D8)
There are multiple ways. I would personally use an array formula, but that may be a bit advanced and overly complicated.
I suggest adding a column E "Month" - into E2 add:
=MONTH(B2)
Then copy cell E2 to E3:E8.
Now you can easily get a monthly average by applying the AVERAGEIF command:
=AVERAGEIF(E2:E8,2,D2:D8)
The second argument, 2, indicates February, but may be exchanged with any number from 1-12.

Pivot table to return the FIRST value in a range

Glad to be joining the forum.
My question deals with attempting to return the FIRST value that occurs over several columns of data, using a pivot table that is filtered within a narrow time range. My current pivot table works by counting values in each column over the time rows. However I'm really only interested in the FIRST value that I come across for each person. So the raw looks something like this:
Person|TimeValue|Variable1|Variable2
1 | 1 | 1 | 0
1 | 2 | 1 | 0
2 | 1 | 1 | 0
2 | 2 | 0 | 1
What I currently get for a pivot using a range of time1 to time 2 is
1 | |2 | 0
2 | |1 | 1
Clearly, the time range I select includes MULTIPLE values in the same column, leading to counts of >1. What I'm thinking is that there is a way to use the same time sorting, but count only the FIRST time a value occurs in that variable, so that the pivot reports only the first time a value occurs within the range for the variables of interest.
Is there a simple way, or am I going to have to do this in VBA?
Much appreciated for any and all help. This is my first more complicated attempt with the newer pivots.
This is probably not the problem you would want to solve using a pivot table. You could just use the VLOOKUP Excel function to solve this issue in a simple way. VLOOKUP will always return the first value in the lookup range that matches the lookup value.

Excel Formulas: Show total based on date entry

I've got a spreadsheet with two columns that represent the number of processed records, and the date the records were processed. In some cases, the records can be processed in multiple batches, so the document looks something like this:
33 4/1/2009
22 4/1/2009
12 4/2/2009
13 4/4/2009
36 4/4/2009
I'm trying to add a new set of columns that contain a date, and shows the total number of records for that date, automagically:
4/1/2009 55
4/2/2009 12
4/3/2009 0
4/4/2009 49
I know how to do this algorithmically, and I could probably manipulate the spreadsheet outside of Excel, but I'm trying to do this in the live spreadsheet, and am a bit bewildered as to how to pull it off.
Any ideas?
Thanks!
IVR Avenger
Will the SUMIF function work for you? SUMIF([range],[criteria],[sum_range]) I think you could set range = the set of cells containing dates in your first listing, criteria would be the cell containing the date in the second listing, and sum_range would be the counts in the first column of your first listing.
I would suggest using a Pivot Table. Put the dates into the row area and 'sum of' records in the data area. Nothing in the columns area.
A pivot table will be more dynamic than a formula solution because it will only show you dates that exist.
Assuming your dates are in column B and the numbers to be accumulated are in A, you could try something like this:
| A | B | C D
1 | 33 | 4/1/2009 | =MIN(B:B) | {=SUM(IF(B1:B5=C1,A1:A5,0))} |
2 | 22 | 4/1/2009 | =C1+1 | {=SUM(IF(B1:B5=C2,A1:A5,0))} |
3 | 12 | 4/2/2009 | =C2+1 | {=SUM(IF(B1:B5=C3,A1:A5,0))} |
4 | 13 | 4/4/2009 | =C3+1 | {=SUM(IF(B1:B5=C4,A1:A5,0))} |
5 | 36 | 4/4/2009 | =C4+1 | {=SUM(IF(B1:B5=C5,A1:A5,0))} |
Note the {} which signifies an array formula (input using Control-Shift-Enter) for any non-trivial amount of data it's heaps faster than SUMIF().
I'd be inclined to define dynamic names for the A1:A5 and B1:B5 parts, something like
=OFFSET(A1,0,0,COUNT(A:A),1)
so that I didn't have to keep fixing up my formulae.
There's still a manual element: adding new rows for extra dates, for example - that might be a good place for a little VBA. Alternatively, if you can get away with showing, for example, the last 90 days' totals, then you could fix the number of rows used.

Resources