Excel sumifs until a new value in column - excel

I have some data that looks like:
Day Result
1-Nov 1
0
1
2-Nov 1
3-Nov 0
0
4-Nov 1
There are other columns with data. I only have the date once as the data is displayed graphically in a time series.
Now I'd like to setup a summary table that aggregates each day. I cannot use sumifs because the date is only in the data once.
How could I write a calculation such that excel sees a2 has a value so sums b2,b3,...bi until ai has a value.
Preferably not vba, never learned it and want to do this in excel rather than R or Python.
EDIT:
I am specifically looking at how to do calculations on the result column grouped by each date. Blank cells should be considered the same date. So when excel sees 1-Nov it then does a calculation (i've said sum but any we can extend to) on 1,0,1 and then stops and a new calculation is done for Nov-2.

IMHO, instead of using a table like this:
Day Result
01/nov 1
0
1
02/nov 1
03/nov 0
0
04/nov 1
You should populate the "Day" column and use a pivot table to summarize the results.
I.e.:
Day Result
01/nov 1
01/nov 0
01/nov 1
02/nov 1
03/nov 0
03/nov 0
04/nov 1
And the pivot table:

Related

Count of Excel based on 2 column criteria and counting the 3rd column

I need a count of how many date items fall within Data 1 & Data 2
ie:
x-1 will have a count of 2
x-2 will have a count of 1
-x-3 will have a count of 2
-y-1 will have a count of 2
What would be the best way to go abouts when approaching this?
Data 1
Data 2
Date
x
1
Date 1
x
1
Date 1
x
1
Date 2
x
2
Date 3
x
2
Date 3
y
1
Date 1
y
1
Date 1
I see only one way to interpret with the available information:
To count the number of times Date_to_test falls within Date_1 and Date_2 (screenshot below, sheet here), you could use either the sum or something like a countifs (with interim calc):
sum approach
=SUM(1*($C$2:$C$11<=$B$2:$B$11)*($A$2:$A$11<=$C$2:$C$11))
countifs + interim calc
helper
=1*(C2<=B2)*(A2<=C2)
(additional column, drag down)
countifs
=COUNTIFS($D$2:$D$11,1)
Screenshot
Alternative
as for the 'sum' approach, sumproduct variants (e.g. =SUMPRODUCT(1*($C$2:$C$11<=$B$2:$B$11),1*($B$2:$B$11>=$A$2:$A$11))) are calculation/memory intensive
despite the countifs + helper approach containing more 'visible' data - these values need only be calculated once, the countifs can then be determined independently (assuming no updates to the helper column) - thus making it more memory/calculation efficient depending upon your calculation mode, screen-updating preferences
Caveat
if, by some misfortune re: interpreting your question, you are referring to some other means of establishing whether "date items fall within Data 1 & Data 2", then without knowing what this is, there very low likelihood of being able to guess this correctly

How to create a ranged frequency table using Excel Cube functions

What I want is to create something like this (see image) in Excel that pulls in the frequency of my chosen category from a table within my PowerPivot data model. The output would also need to be dynamically filtered via a cell reference.
Using the below data set as an example:
Week 1 A
Week 1 A
Week 1 A
Week 1 A
Week 1 A
Week 1 B
Week 1 B
Week 1 C
Week 1 D
Week 2 A
Week 2 A
Week 2 A
Week 2 A
Week 2 A
Week 2 A
If I filtered to Week 1 through my set expression, the following output would be produced
1 2
2-4 1
5+ 1
However, if filtered to Week 2, this output would be produced
1 0
2-4 0
5+ 1
I say 'set expression' because I am assuming the way to do this is through the CUBESET function possibly with a MDX FILTER function and the CUBESETCOUNT functions though I am open to other suggestions. Even though the example doesn't show it, I need the expression to filter multiple dimensions from my cube, in particular, date, which is found in my calendar table.
I also understand that I could create specific measures within PowerPivot to handle this (sample formula below), but I would like to know if this is possible via the CUBESET function.
Freq (5+):=CALCULATE(
DISTINCTCOUNT([myColumn]),
FILTER(myTable,
COUNTROWS(FILTER('myTable', [myColumn] = EARLIER([myColumn]))) >=5 )
)
I am also open to creating a helper column within my Powerpivot table.
Thanks,

Grand total for pivot table not giving me the correct amount when using a calculated field

I have a pivot table that I put a calculated field in. the calculation is =IF(fddue_date<finspectData,0,COUNT(fLotSize))
The problem is that instead of getting the expected result of 6 I get 1. Any one have an idea what I am doing wrong?
Row Labels Count of fLotSize Sum of Field1
5/14/2014
5/12/2014 1 0
5/14/2014 7 1
5/15/2014 9 1
5/16/2014 5 1
5/19/2014 3 1
5/30/2014 1 1
6/9/2014 1 1
Grand Total 27 1
This is a side effect of the calculated field and it treats the grand total the same way as any other row in the pivot table.
If you want to use this type of calculated formula and have a sum shown in the grand total, the best way is to create the formula in the source data table and then pull it into your pivot table as a separate column which will show the correct grand total.
it's by the way a known bug since at least Excel 2003. still in 2013 ...
https://support.microsoft.com/en-us/kb/211470

Sum elements in matrix in Excel

id a b c
1 0 0 0
1 0 0 0
2 0 0 0
2 0 0 0
3 1 2 3
3 0 0 1
Given the above matrix, I want to create a new matrix, which sums the numbers within the first matrix for a given id in a given year (a,b or c). So for the above, it should look like:
1 2 3
a 0 0 1
b 0 0 2
c 0 0 4
Can anyone see what to do?
Try using SUMPRODUCT rather than SUMIFS, e.g.
=SUMPRODUCT(B2:D7,(B1:D1="a")*(A2:A7=1))
The formula solution given in the other responses will work well when data headings are already in place and the data range is not too large.
A pivot table creates the row and column headings for you and will update as new data is added when you click the Refresh Button, it's also significantly quicker when the data range is large.
Steps
A) Choose Insert | Table for your data range, and give it a suitable name, the default is Table1
B) Access the PivotTable wizard via the shortcut Alt+D+P (this is not on the default menus).
1) Multiple Consolidation Ranges
2a) I will Create the Page Fields
2b) Range: Table1[#All] Page Fields: 0
2c) Existing Worksheet: $A$7
C) Click Finish, switch Row and column fields and turn off totals and autoformatting
I suggest that you try solving that problem with pivot tables.
Here are 2 links that you might use to learn that feature:
http://www.cpearson.com/excel/pivots.htm
http://www.youtube.com/watch?v=7zHLnUCtfUk
The only drawback with Pivots is that if the size of the source range changes, the Pivot will not adjust automatically. So once you managed to solve your initial problem and understand the power of Pivot Tables, I suggest that you use a Dynamic Named Range as the source of your Pivot.
Edit:
I feel that barry houdini's solution is simpler. I reproduced it below (with all credit belonging to him!)

Excel 2010 If duplicate merge cell corresponding data

I've got duplicate dates in my first column. I have corresponding ratings in the next columns. My goal is to combine the ratings into all one date only if they are duplicate dates. I have many duplicate dates and for each duplicate I simply want to combine the numbers:
DATE 5STAR 4STAR 3STAR 2STAR 1STAR
12/2/2009 0 1 0 0 0
12/2/2009 1 0 0 0 0
4/6/2011 1 0 0 0 0
4/6/2011 1 0 0 0 0
So in the example above I would want to be left with:
DATE 5STAR 4STAR 3STAR 2STAR 1STAR
12/2/2009 1 1 0 0 0
4/6/2011 2 0 0 0 0
Assuming that your original sheet is called "duplicate data" and that you have created a second sheet called "combined data" and which has exactly the same format but with only one row per date, but this formula in B2 of combined data and drag down and over as far as necessary:
=SUMPRODUCT(('duplicate data'!$A$2:$A$5='combined data'!$A2)*'duplicate data'!B$2:B$5)
In Excel 2007 and 2010 you can easily remove duplicate dates using Remove Duplicates in the Data tab. In XL 2003 I believe you'd use the Advanced Filter in the Filter item of the Data menu.
If you're going to be doing this more than once, I'd look at normalizing your data a bit so that you could do this with a pivot table. If I'm guessing correctly that only one column per row ever gets a one, i.e., there's only one rating per row, and your data looked like this...
DATE Rating
12/2/2009 4STAR
12/2/2009 5STAR
4/6/2011 5STAR
4/6/2011 5STAR
... you could easily create a pivot table from it.

Resources