Excel Formula to Calculate Text within a date range - excel

I am trying to calculate values within a specific date range. The data I want to split between each month and the values: Successful, Incomplete and Failed.
I've tried pivot tables with this data but it doesn't work for me, also lacking pivot table excel experience. Formulas I'm more comfortable with.
I am using the following statement to at least get the total number of a value I add into it;
=COUNTIF('Jan 19'!$C$2:$C$1159,"Value")
Ex. If I put into the value "Successful" I get the total number of successful records.
I am looking into having a formula that I can input a specific month/date range (Jan, Feb, etc) and a value to get a count.
Ex. =Formula ((RangeOfData, "Value") AND (RangeOfData, (FromDate, ToDate))
I expect to the get the total number of a value(s) within a specific date range. If there isn't any data then the results would be blank or 0.

I'd use the formula COUNTIFS() as #cybernetic.nomad pointed in the comments so you can put more conditions on the COUNT:
=+COUNTIFS('Jan 19'!$B$2:$B$1159,">="&F3,'Jan 19'!$B$2:$B$1159,"<"&G3,'Jan 19'!$C$2:$C$1159,H3)
In the formula above I guessed the dates are in the COLUMN B, if not, you need to change it in the formula above.
To do that we should put the range we want to look at in a couple of cells where you would put the date range, in the example above:
F3 is the start date (if you want February of this year should be 1/2/2019).
G3 is the final date (if you want February of this year should be 1/3/2019).
H3 is where you can write "value", "successful" or any other string you are trying to count.

Related

Excel returning multiple values for a date range, with a single date items summed

I have the opposite query for this question:
Excel - Lookup to return multiple values in between date range
The solution is given for the above query in the following link also:
https://www.get-digital-help.com/2009/12/13/formula-for-matching-a-date-within-a-date-range-in-excel/
But my query is that for multiple date ranges, how do I find the total bookings of a single date.
I wish to build a calendar which will allow me to work out how many booking I have for a certain day. All the bookings are for 1 or more items and I want the total items which will be there on a single day, across a date calendar range.
On the calendar on the right side, I wish to add the total items which will be staying over during that specified date.
So, in the example, on the 26th December, a total of 6 items will be there. And for 5th December there is only 1, while for 1st December there are no items.
Would like to have these numbers in the calendar on the right.
I have tried using VLOOKUP, LOOKUP, INDEX and MATCH.
Also, tried the SUMPRODUCT mentioned, but those seem to give a single range and number for that range, but not the multiple values across a date range.
https://chandoo.org/wp/range-lookup-excel/
Formulae I tried are, for the 26th December date are:
=(LOOKUP(H10,((Table1[Date From]):(Table1[Date To])),Table1[Items from]))
=SUMIF(Table1[Item],(LOOKUP(2,1/(Table1[Date From]<=H10)/(Table1[Date To]>=H10))))
=INDEX(Table1[Item from],MATCH(H10,LOOKUP(H10,Table1[[Date From]:[Date To]])))
For Dec 26th (and keeping your original structure)
=SUMIFS(Bookings[[Items]:[Items]],Bookings[[Date From]:[Date From]],"<=" &H10,Bookings[[Date To]:[Date To]],">="&H10)
Note that I used the absolute address structured reference form so you can at least fill/drag across a row, without changing the columns from the table.
If you want to make things even easier, you can replace the H10 reference with a computed reference, but at the cost of using OFFSET which is a volatile function.
=SUMIFS(Bookings[[Items]:[Items]],Bookings[[Date From]:[Date From]],"<=" &OFFSET(H$1,ROW()-2,0),Bookings[[Date To]:[Date To]],">="&OFFSET(H$1,ROW()-2,0))
You might also be able to construct a computed cell reference using the INDEX function, which would be non-volatile.
Updated answer with array formulas
Sorry for not understanding your first request.
You can use the following array formula in a "single cell"
{= SUM( IF( (E2 >=$B$2:$B$8 ) * (E2<=$C$2:$C$8) ; $A$2:$A$8 ; 0 ))}
Where column e contains the target dates, columns a, b and c contain items, from and to.
This formula is expansible and copiable to other cells where e2 will be relatively changed for each target date. This is easily adaptable to your month table. Put the formula below the first date, then expand horizontally and copy/paste to the other rows.
See picture:
Old answer
Create a separate cell with your target date. Suppose $e$1.
Create on e2 this formula: =if( and( $e$1 >= c2 ; $e$1 <= d2 ); a2; 0)
Expand it and sum at the bottom.
Sorry for my formulas in Portuguese in the image (se = if ; e = and):

Can't get CUBEVALUE to filter by date value in cell

My data model has a column named rowDate. This column has several repeating instances of dates due to the fact that there are multiple rows of data for different times of a single day.
I've written a measure that sums the values in another column from the data model that I want to pull from. (We'll call this MyMeasure.)
I'm trying to write a CUBEVALUE formula that extracts the total of MyMeasure when rowDate equals the value of a cell in a worksheet. (This will allow the result of the CUBEVALUE to change based on the date that the user inputs into cell B2.)
e.g.
Cell B2 = "2018-06-29" (date formatted)
=CUBEVALUE("ThisWorkbookDataModel","[MyMeasure]","[Summary Data].[rowDate].["&$B$2&"]")
This always returns #N/A. I have another column with data (a number) that I can write the exact same CUBEVALUE formula, but referencing the appropriate cell, and it works just fine. It's just this date column that I can't figure out.
Found the solution in this thread. The trick is to format the date in your targeted cell inline using the TEXT function to match the cube's default date format (YYYY-MM-DDTHH:MM:SS).
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[MyMeasure]","[Summary Data].[rowDate].&["&TEXT($B$2,"YYYY-MM-DDTHH:MM:SS")&"]")

Excel countifs on date table column

I have a excel table, with various columns,
Date, Name, LE, and so on. In LE column values are either L or E.
Date, Name, LE
4/4/2018, Jan, L
4/3/2018, Jed, L
4/1/2018, Jan, L
3/25/2018, Jan, E
Note actual date is like 4/4/2018 but formatted so it display like 4-April-18
Now I want to count how many times L appears for a particular name in a particular month. For example in month of March, ABC has XXX L.
At this time I am adding additional column after date column which display month's number from date column. But I don't like to have additional column and finding ways to directly check month from date column.
My formula is like this:
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", tblXYZ[Month],"Mar")
It work fine and give required result.
But when I try
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", tblXYZ[Date],"Mar")
it don't work,
when I use MONTH() with table column it don't work and generate error
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", Month(tblXYZ[Date]),3)
so I have to extract month from Date column directly in the formula but I am unable to find a way.
I am using Excel 2013.
In general the first parameter of CountIfS() is a range, and pretty much you are trying not to give a range, but an array of months, thus SUMPRODUCT() suits you way better:
COUNIFS support.office.com
This is for a single condition:
=SUMPRODUCT(--MONTH(tblXYZ[Date]=3))
This is for two conditions:
=SUMPRODUCT(--MONTH(tblXYZ[Date]=3)*(tblXYZ[LE]="L"))
The --MONTH(tblXYZ[Date]=3) is a trick, converting boolean data to 0 and 1. You can see how it works with Ribbon>Formulas>Evaluate Formulas in Excel.
Try this -
=COUNTIFS(tblXYZ[Name],"ABC", tblXYZ[LE],"L", tblXYZ[Month(Date)],"3")

Excel - automatically generate list of dates, given multiple date ranges in one column

I better show you. This is how my list looks like:
And this is how I want it to be:
Basically, in the first picture I have different date ranges, for each date range I have a those two metrics, Sessions and Users and the final result should be a sort of explosion of all date ranges into single dates, considering that certain dates can be included in more than 1 date ranges (e.g. date 2017-08-12) is included in both first and second row.
And last but no least, the end date shouldn´t be counted.
Can someone help me out?
Thanks a million
A.
This is the outline of a solution:
Split each from/to date in your input table into its 2 constituent dates. You will need to use the string functions (LEFT, RIGHT and MID) to extract the numbers for the year, month and day values. These will still be strings of characters, so use the VALUE function to convert them to actual numbers and then use the DATE function to assemble them into a proper date value in Excel. (You may need to format your results using a date format, as Excel stores its dates as number of days since 01/01/1900, so 11/08/2017 is held in Excel as 42958.) Add as many helper columns as you need to your input table to achieve this.
Subtract 1 from each end date, this corrects the dates ranges so that the end date is included.
The first start date and the last end date define the range of output dates. So start your output table with the first date and in the cell below use a formula to add 1 to this date and copy the formula downwards until you get to your last possible output date.
To get the results for each possible output date, you need to find
which date ranges it belongs to. It belongs to a date range if it is
greater than or equal to the range's start date and less than or
equal to the end date. However, rather than comparing each output
date with individual start and end dates it is possible to compare
each output date with all the start and all the end dates at once. An expression such as A10>=E2:E7 generates an array of 6 elements with values
TRUE and FALSE according to whether A10 is greater than or equal to
E2, E3, E4, E5, E6 and E7 respectively. So, you can use this approach to generate an array of TRUE/FALSEvalues showing whether a particular output date is greater than or equal to (ie on or after) each range's start date. Similarly, you can get an array showing whether the same output date is less than or equal to (ie on or before) each range's end date.
The versatile SUMPRODUCT function can now be used to combine the arrays and the relevant sessions/users values from the input table to get the relevant values for the output date. For example, if the start dates are in E2:E7, the end dates in F2:F7, the sessions in B2:B7 and the output date in A10 then a sutable formula for determining the number of sessions to attribute to the output date would be =SUMPRODUCT(($A10>=$E$2:$E$7)*($A10<=$F$2:$F$7)*(B$2:B$7)). This formula could be copied to give results for all output dates and, assuming the input data for users is in C2:C7, it will also give the results for users if copied into the column adjacent to the sessions results. In this formula, the TRUE and FALSE values are effectively converted to 1 and 0, respectively.
A few points: (i) if you don't know how dates work in Excel then find out, it makes tasks such calculating the number of days between two dates or the date n days before/after a particular date extremely easy using simple arithmetic; (ii) don't confuse strings of text which look like dates with dates that can be manipulated arithmetically in Excel; (iii) I believe there are some errors in your example - 16/08/2017 is a date in two of your input ranges and should have results of (2,2) not (1,1) and 17/08/2017 is similarly in error.
I have used this approach in the illustration below and, to test its robustness, I have added an extra row of input data which has sessions different from users and which yields one date (19/08/2017) which does not match to any input range.
The output date range was generated as follows:
Cell A10: use formula =E2
Cell A11: use formula =1+A2
Cells A12, A13, ... copy formula in cell A11

SUMIFS in Excel with cell reference

I'm trying to sum the values in sheet GLTB column D where the value in column A starts with 2.21 and the value in column E is equal to the date in the cell A1. I tried this formula:
=SUMIFS(GLTB!$D$3:$D$26522,GLTB!$A$3:$A$26522,"2.21*",GLTB!$E$3:$E$26522,GLTB!$A$1)*-1
The problems:
The date in A1 doesn't appear anywhere else on the GLTB sheet, so I should get 0 for a sum, but I don't. I get some number that doesn't correspond to anything I can find.
I can make all the values in column D where column A starts with 2.21 equal to 0 (or any other number) and it has no effect on the result of the formula.
I tried this formula based on answers to other questions:
=SUMIFS(GLTB!$D$3:$D$26522,GLTB!$A$3:$A$26522,"2.21*",GLTB!$E$3:$E$26522,GLTB!"="&$A$1)*-1
This just changes the last criterion reference. However, Excel gives me a formula error response.
Any ideas?
This should get you a little closer:
=SUMIFS(GLTB!$D$3:$D$26522,GLTB!$A$3:$A$26522,">=2/21/16",GLTB!$E$3:$E$26522,GLTB!$A$1)*-1
This assumes that column A contains date values which are formatted as string. If these values are not date values, then please give some example of what cell contents in column A.
Note: I'm not clear on why you're searching for "2.21*" so I used the >= operator. That can be changed, or we could add additional criteria to the SumIfs based on your needs.
Other things to be careful of:
Ensure that column E and cell A1 both contain the same type of data (either date formatted as string, or string data representing dates. If you have inconsistent data types, the equivalence test in your Criteria2 (GLTB!$E$3:$E$26522,GLTB!$A$1) will not return the desired results.
To start with, you should format your data as table. To do this, use "Start > Format as table". This will also give you the option of giving your table a name, e.g. data. Basically this makes performing the following steps easier.
From then on, you don't need to reference with GLTB!$A3:$A26522anymore, but can use data[ColumnA].
I'm assuming you have a column ValueA with something in there that might start with 2.21, then ValueD which you want to sum and DateE which should be equal to a certain date.
The formula you are looking for is not SUMIF, but the much better SUMPRODUCT, as this allows you to check multiple conditions.
The final formula will look like this:
=SUMPRODUCT((data[DateE]=A1)*(LEFT(data[ValueA],4)="2.21")*data[ValueD])
Now what does this do. SUMPRODUCT first builds a product and then sums that up. Let's assume the following values:
A1 = 2016-03-01
DateE = 2016-03-01
ValueA = 2.213454
ValueD = 3
The formula will then do the following:
(2016-03-01=2016-03-01) is 1
("2.21" = "2.21) is 1
3 is 3
1*1*3 = 3
Now if you change the date in A1, the value of your SUMPRODUCT cell should change accordingly.
As a starter I recommend using Tables - it's much easier to read and maintain your data: Insert-->Table.
e.g.
Here I have "Table1", with the Date column formatted as a Short Date.
Name Date Quantity
Alpha 17-Mar-16 1
Beta 15-Feb-16 2
Charlie 11-Mar-16 3
Dog 11-Feb-16 4
Echo 9-Feb-16 4
Foo 6-Jan-16 5
Then in a separate row/cell, you can input a formula to sum the quantity column where the data is from 1st Feb onwards.
Here I've used a different date format, but Excel is fine with it.
Feb Onwards Total: 14 =SUMIFS(Table1[Quantity],Table1[Date],">=01-Feb-16")
Feb Only Total: 10 =SUMIFS(Table1[Quantity],Table1[Date],">=01-Feb-16", Table1[Date],"<29-Feb-16")
Try something like this:
=SUMPRODUCT((INT(GLTB!$E$3:$E$26522)=INT(GLTB!$A$1))*(ROUNDDOWN(GLTB!$A$3:$A$26522,2)=2.21)*(GLTB!$D$3:$D$26522))
If this Returns and error, then one of two things:
your dates are not true dates but text that look like dates.
your have errors in your cells in some of the columns.

Resources