EXCEL formula to sum demand per date when multiple entries of dates exist - excel

How do I sum the amount of demand I have for each date, when there are multiple entries for each date., e.g.
Sheet 1:
A B
Date Demand
13/7/21 5
13/7/21 4
13/7/21 2
15/7/21 6
15/7/21 3
16/7/21 2
16/7/21 4
So I'm trying to get a summary as follows:
Sheet 2:
A B
13/7/21 11
14/7/21 0
15/7/21 9
16/7/21 6
17/7/21 0
I've tried =SUMPRODUCT(--('Sheet 1'!$A$2:$A$240='Sheet 2'!A2),'Sheet 1'!$B$1:$B$240)
I'm not wanting to do a pivot table, as the pivot table does not give me the zero values for dates where there is no data (unless there is a way to show this in a pivot)

You can use SUMIFS() like
=SUMIFS(Sheet1!B:B,Sheet1!A:A,A1)
You can also use SUMPRODUCT() in this way.
=SUMPRODUCT((Sheet1!$B$2:$B$8)*(Sheet1!$A$2:$A$8=A1))

Put together quickly to start you off:
Edit to give text version of the solution to the OP's problem:
=SUMIFS(B6:B12,A6:A12,"="&G12)
Then you can do between by setting lower and upper criteria in the sumifs().

Related

Count specific column values by year in another date column in Excel

I have an excel table with two columns and several hundred rows. One column lists a single-digit code that represents an event, the other the date of that event. I'm attempting to count the number of times a particular event (say "1") occurred in a particular year (say 2017).
I normally use "COUNTIFS" for two or more criteria, but I'm stumped by the date format. I can't seem to get it to work in the formula. In this case, I'm using the yyyy-mm-dd format. How can I perform this operation?
A small example of the table is as follows:
------------------------
A B
--+--------------------+
1 Event Date
2 1 2016-09-12
3 1 2019-10-11
4 3 2017-03-24
5 2 2016-05-25
6 3 2017-08-02
7 1 2018-10-11
Just use
=COUNTIFS(A:A,1,B:B,">="&DATE(2017,1,1),B:B,"<="&DATE(2017,12,31))
EDIT:
if you have text-that-looks-like-dates, you can use SUMPRODUCT and YEAR:
=SUMPRODUCT((A2:A7=1)*(YEAR(B2:B7)=2017))

Excel 2013 complex countif formula

I have a source sheet set up like this:
Days Open Month
10 1
4 1
6 1
2 1
4 2
2 2
-1 2
4 3
6 3
7 4
3 4
etc
I'm trying to set up a formula to count rows based on the following criteria:
cells in Days Open column <=5 and <>-1 where the month is either 2, 3, or 4 (the worksheet will eventually have month numbers up to 12, and I need to group results quarterly). The total must then be divided by the total of ALL rows in which 2, 3, or 4 appears in the Month column.
I can't seem to get the first part of the COUNTIFS to work with both criteria... this is what I have so far that I'm trying to make work:
=COUNTIFS('Cumulative Complaints'!K:K,"<=5",'Cumulative Complaints'!K:K,"<>-1")/(COUNTIF('Cumulative Complaints'!L:L,"2")+COUNTIF('Cumulative Complaints'!L:L,"3")+COUNTIF('Cumulative Complaints'!L:L,"4"))
I've been looking around here and other excel forums and think maybe SUMPRODUCT is the way to go? I haven't been able to get that to work though, given the criteria needed on the Days Open column (<=5 and <>-1).
Try this SUMPRODUCT() FORMULA:
=SUMPRODUCT(('Cumulative Complaints'!K:K<=5)*('Cumulative Complaints'!K:K<>-1)*('Cumulative Complaints'!L:L>=2)*('Cumulative Complaints'!L:L<=4))/SUMPRODUCT(('Cumulative Complaints'!L:L>=2)*('Cumulative Complaints'!L:L<=4))
When using the SUMPRODUCT the condition AND is replaced with the *. It requires all four conditions to be True to return a 1; 1*1*1*1 = 1 if any are false they return 0 so 1*1*0*1 = 0. So as it iterates through the rows it returns a 1 or a 0 to the be added to the sum.
Wrapping a COUNTIF or COUNTIFS function in a SUM function allows you to use an array of constants as OR citeria.
=SUM(COUNTIFS('Cumulative Complaints'!K:K, "<>"&-1,'Cumulative Complaints'!K:K, "<="&5,'Cumulative Complaints'!L:L, {2,3,4}))/SUM(COUNTIF('Cumulative Complaints'!L:L, {2,3,4}))
This is not an array formula and does not require CSE.
My answer would be to take a different approach.
Excel has a very powerful feature called Pivot Tables, and I think it might be a good fit for your problem and other similar problems you may face.
First, I would add a couple columns to your table, like so:
Days Open Month Quarter RecentlyOpened
10 1 1 FALSE
4 1 1 TRUE
6 1 1 FALSE
2 1 1 TRUE
4 2 1 TRUE
2 2 1 TRUE
-1 2 1 FALSE
4 3 1 TRUE
6 3 1 FALSE
7 4 2 FALSE
3 4 2 TRUE
The formula for Quarter is: =CEILING(B2/3,1)
The formula for RecentlyOpened is: =AND(A2<>-1,A2<=5)
Second, select the table, and do Insert > Pivot Table.
Third, drag from the fields to the boxes, like so:
Drag Quarter to the ROWS box
Drag RecentlyOpened to the FILTERS box
Drag Month to the VALUES box
Fourth, click Sum of Month, and select Value Field Settings to change Sum to Count.
Fifth, set the RecentlyOpened filter to TRUE.
The result is this:
Pivot Tables often provide a solution that is more flexible and easier to read and understand versus complex formulas.

How to get the latest date with same ID in Excel

I want to Get the Record with the most recent date as same ID's have different dates. Need to pick the BOLD values. Below is the sample data, As original data consist of 10000 records.
ID Date
5 25/02/2014
5 7/02/2014
5 6/12/2013
5 25/11/2013
5 4/11/2013
3 5/05/2013
3 19/02/2013
3 12/11/2012
1 7/03/2013
2 24/09/2012
2 7/09/2012
4 6/12/2013
4 19/04/2013
4 31/03/2013
4 26/08/2012
What I would do is in column B use this formula and fill down
=LEFT(A1,1)
in column C
=DATEVALUE(MID(A1,2,99))
then filter column B to a specific value of interest and sort by column C to order these values by date.
Edit: Even easier do a two level sort by B then by C newest to oldest. The first B in the list is newest.
Do you need a programmatic / formula only solution or can you use a workflow? If a workflow will work, then how about this:
Construct a pivot table of your data
Make the Rows Labels the ID
Make the Values Max of Date
The resulting table is your answer.
Row Labels Max of Date
1 07/03/13
2 24/09/12
3 05/05/13
4 06/12/13
5 25/02/14

Count in Excel over a range using 2 columns of data

Tried looking for an answer first...
I want to count the number of items that were open between 1-7 days, 8-14 days, etc etc (open and closed on same day = open for 1 day)
Is there a way I can count this directly using the 2 columns holding the data without creating a 3rd column for Date Closed - Date Opened +1??
So in this example, what can I use to calculate that the number of 1-7 days items is 2? (Items 1 and 3)
Item # Open Closed
1 01/06/2014 01/06/2014
2 05/05/2014 20/06/2014
3 10/06/2014 16/06/2014
4 08/06/2014 15/06/2014
5 02/06/2014 19/06/2014
Many thanks :o)
One way would be to use the versatile SUMPRODUCT:
=SUMPRODUCT(1*(C2:C6-B2:B6+1>7))
assuming your start date column is B and end date column is C. The second part of the formula will determine all date spans which are larger than 7, and the 1* will convert the TRUE values to 1 in order to sum them up.

Find the top n values in a range while keeping the sum of values in another range under x value

I'd like to accomplish the following task. There are three columns of data. Column A represents price, where the sum needs to be kept under $100,000. Column B represents a value. Column C represents a name tied to columns A & B.
Out of >100 rows of data, I need to find the highest 8 values in column B while keeping the sum of the prices in column A under $100,000. And then return the 8 names from column C.
Can this be accomplished?
EDIT:
I attempted the Solver solution w/ no luck. 200 rows looks to be the max w/ Solver, and that is what I'm using now. Here are the steps I've taken:
Create a column called rank RANK(B2,$B$2:$B$200) (used column D -- what is the purpose of this?)
Create a column called flag just put in zeroes (used column E)
Create 3 total cells total_price (=SUM(A2:A200)), total_value (=SUM(B2:B200)) and total_flag (=(E2:E200))
Use solver to minimize total_value (shouldn't this be maximize??)
Add constraints -Total_price<=100000 -Total_flag=8 -Flag cells are binary
Using Simplex LP, it simply changes the flags for the first 8 values. However, the total price for the first 8 values is >$100,000 ($140k). I've tried changing some options in the Solver Parameters as well as using different solving methods to no avail. I'd like to post an image of the parameter settings, but don't have enough "reputation".
EDIT #2:
The first 5 rows looks like this, price goes down to ~$6k at the bottom of the table.
Price Value Name Rank Flag
$22,538 42.81905675 Blow, Joe 1 0
$22,427 37.36240932 Doe, Jane 2 0
$17,158 34.12127693 Hall, Cliff 3 0
$16,625 33.97654031 Povich, John 4 0
$15,631 33.58212402 Cow, Holy 5 0
I'll give you the solver solution as a starting point. It involves the creation of some extra columns and total cells. Note solver is limited in the amount of cells it can handle but will work with 100 anyway.
Create a column called rank RANK(B2,$B$2:$B$100)
Create a column called flag just put in zeroes
Create 3 total cells total_price, total_value and total_flag
Use solver to minimize total_value
Add constraints
-Total_price<=100000
-Total_flag=8
-Flag cells are binary
This will flag the rows you want and you can grab the names however you want.

Resources