COUNT Function Excel - excel

I have the following table:
oDate oValue
-------------------------------
2019-01-01 00:00 90
2019-01-01 00:30 90
2019-01-01 01:00 86
2019-01-02 00:00 86
2019-01-02 00:30 90
2019-01-02 01:00 86
2019-01-02 01:30 90
I want to have the following result:
oDate 90 86
-----------------------------------
2019-01-01 2 1
2019-01-02 2 2
I want to have the count of each oValue for each different oDate.
Does anyone have the idea for this case?
Thank you.

Put this under the 90 in the second table then drag right and down.
=COUNTIFS($A:$A, ">="&$D2, $A:$A, "<"&$D2+1, $B:$B, E$1)

COUNTIFS as given in another answer in my opinion is the way to go. However if you are interested in seeing other potential methods, you could do this with SUMPRODUCT. The reason I advise against it is as the data gets large, you can wind up doing an extrodinary number of calculations. Also with SUMPRODUCT, since it is performing array calculations, full column references should be avoided. Where as with COUNTIFS full column references wont make a difference.
So with SUMPRODUCT and assuming the layout in the picture below, use the following formula in C13 and copy down and to the right as required.
=SUMPRODUCT((INT($B$4:$B$10)=$B13)*($C$4:$C$10=C$12))
Adjust the ranges to suit your data.

Related

time in position - excel dates

given the following excel table
I'm trying to add a column with the number of days in a position, my problem is that the 'starting date' for an employee (column b) is the same. This is why I'm struggling with column D creation.
For example: emp 111 the first row is DAYS(B2,C2), but for the second row should be (C2,C3).
I tried to do it with index match array but I can't make it work.
How do I do this kind of calculation?
emp_number
start_working_date
promotion_date
111
2020-01-01
2020-02-04
111
2020-01-01
2020-04-23
111
2020-01-01
2020-08-20
112
2020-03-01
2020-05-01
112
2020-03-01
2020-07-01
113
2020-04-01
2020-08-01
114
2020-05-01
2020-09-01
115
2020-06-01
2020-10-01
Use an IF with MATCH to test if it is the first or not, then subtract from the correct cell:
=IF(MATCH(A2,A:A,0)=ROW(),C2-B2,C2-C1)
Note this only works if the data is sorted correctly. Emp_Number then Promotion_Date.
If the data is not sorted then we can use:
=IF(COUNTIFS(A:A,A2,C:C,"<"&C2)=0,C2-B2,C2-MAXIFS(C:C,A:A,A2,C:C,"<"&C2))
The obligatory discussion on the difference between *IF(s)() and MATCH(). Match is much less intensive on the calcs and as such if it can be done sorting the data and using the first formula will be much more performant.
It will not be noticeable on a dataset of less than a couple thousand. But once the dataset gets above 10,000 the calc times will increase and at some point will fail when using the *IF(s)() function.
You may also try using this, but in your query you have mentioned it wrong since, the syntax of DAYS Function is DAYS(end_date,start_date) where as you have provided as DAYS(start_date,end_date).
• Formula used in cell D2
=IF(COUNTIF($A$2:A2,A2)=1,DAYS(C2,B2),DAYS(C2,C1))

Filtering discrepancies in duplicate measurements

I have a dataset with the following problem.
Sometimes, a temperature sensor would return duplicate readings at the exact same minute, where sometimes 1 of 2 of the duplicates is "reasonable" and the other is slightly off.
For example:
TEMP TIME
1 24.5 4/1/18 2:00
2 24.7 4/1/18 2:00
3 24.6 4/1/18 2:05
4 28.3 4/1/18 2:05
5 24.3 4/1/18 2:10
6 24.5 4/1/18 2:10
7 26.5 4/1/18 2:15
8 24.4 4/1/18 2:15
9 24.7 4/1/18 2:20
10 22.0 4/1/18 2:20
Line 5, 7 & 10 are readings that are to be removed as they are too high or low (doesn't make sense that within 5 minutes it will rise and drop more than a degree in a relatively stable environment).
The goal at the end with this dataset is to "average" the similar values (such as in line 1 & 2) and just remove the lines that are too extreme (such as line 5 & 7) from the dataset entirely.
Currently my idea to formulate this is to look at a previously obtained row, and if one of the 2 duplicates is +/- 0.5 degree, to mark in a 3rd column with TRUE so I can filter out all the TRUE values in the end. I'm not sure how to communicate within the if statement that I'm looking for a + OR - 0.5 of a previous number however. Does anyone know?
Here is a google sheet example that does what you want:
https://docs.google.com/spreadsheets/d/1Va9RjSeulOfVTd-0b4EM4azbUkYUb22jXNc_EcafUO8/edit?usp=sharing
What I did:
Calculate a column of a 3-item running average of the data using "=AVERAGE(B3:B1)"
Filter the list using "=IF(ABS(B2-C2) < 1, B2, )"
Calculate the average of the filtered list
The use of Absolute Value is what provides "+ OR -" that you were looking for. It is saying if the distance between two numbers is too much, then don't include the term.
So, A Simple Solution came to my mind. Follow the Following steps given below:
Convert Data to Table
Add a 4th column at the last
Enter the formula "Current Value - Previous Value"
Filter the Column with high difference values
Delete those rows of filtered data and you'll be left with Normal Values
Here's the ref. Image
Or If you want to consider the Same time difference only then do the following:
Convert your data to Table
Add 4th column at the end of table
Writhe the Following Formula to 4th Column
IF(Current_Time = Previous_Time, Current_Temp-Previous_Temp,"")
Filter and Delete the Data with high Difference
See the following Image:

Look up Cell data based on Month header in table with two cells as reference

Some days ago i got help from Scott Craner with an formula for a 3D index match which works great.
I have tried expanding on it without any results, hopefully you can point out what i'm doing wrong.
Output list
Group Division Input Verification Differance
G1 1 120 123 =Sum([#[Input]]-[#[Verification])
G2 2 76 110 =Sum([#[Input]]-[#[Verification])
G3 3 110 90 =Sum([#[Input]]-[#[Verification])
G4 4 34 53 =Sum([#[Input]]-[#[Verification])
Data list
Group Division Year Jan Feb Mar Apr
G1 1 2017 123 95 80
G2 2 2017 110 85 75
G3 3 2017 90 80 70
G4 4 2017 53 53 46
Following code is the one im trying to use, using only Group as a lookup i get a value
=INDEX(DataList,MATCH([#Group]:[#Division],DataList[Group]:DataList[Division],0),MATCH(TEXT($A$1,"mmm"),DataList[#Headers],0))
I have tried different variations,
Binding the results together with an &,
Tried binding just one result with & and the other one with a simple :
nothing has produced a good result in some cases i get a result, in others i do not get anything.
If i only use Group as a lookup term it's not an issue, it returns the correct value, but I'm trying to Index match two cells with two other cells.
I have evaluated the code and it does not return a value and I do not know what i'm doing incorrectly

Summing every first month columns in Excel

I am trying to add the sum of the first 7 columns and then the next 7th columns etc in Excel. So for example if I have the below data and I needed to be added weekly,
Day 02/01/2017 03/01/2017 04/01/2017 05/01/2017 06/01/2017 07/01/2017 08/01/2017 09/01/2017 10/01/2017 11/01/2017 12/01/2017 13/01/2017 14/01/2017 15/01/2017
Presented Calls 1000 1550 900 1455 789 987 1435 1200 1675 1230 1232 1400 999 650
So if I want to add the presented calls from 02/01 - 07/01 this should be sum(B2:H2)
Then the sum of the presented calls from 08/01-15/01 this should be sum(I2:M2)
etc
However at the moment in Excel it is being sum(B2:H2) then sum(C2:I2) which is incorrect, can anyone help?
You can use the OFFSET() function combined with the COLUMN() function and a bit of arithmetic to get the desired range to sum.
Try entering this formula and fill across.
=SUM(OFFSET($B$2,0,(COLUMN()-COLUMN($B$2))*7,1,7))

Why does a specific arrayformula not work in google sheets but works fine in excel

This is in continuation to how to calculate XIRR dynamically in excel and in google sheets
The proposed array formula** solution (mentioned below) works perfectly fine in excel
=XIRR(INDEX(F:G,N(IF(1,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)),ROW(INDEX(A:A,1):INDEX(A:A,COUNTIF(B$2:B$8,J2)))))),N(IF(1,{1,2}))),CHOOSE({1,2},INDEX(A:A,N(IF(1,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)),ROW(INDEX(A:A,1):INDEX(A:A,COUNTIF(B$2:B$8,J2))))))),TODAY()))
but the same solution refuses to work in google sheets with the error
In XIRR evaluation, the value array must include positive and negative numbers.
Any idea why this is not working in google sheets and how to make it work?
Source data
PurchaseDate Script No.ofunits PurchNAVrate NetAmount ForXIRR TotalReturn
17/11/2014 A 2241 33 75000 -75000 96000
8/1/2015 B 53 649 35000 -35000 43000
14/1/2015 B 75 658 50000 -50000 61500
14/10/2014 C 2319 32 75000 -75000 108000
8/1/2015 D 318 109 35000 -35000 40000
14/1/2015 D 450 110 50000 -50000 57000
8/6/2015 D 175 114 20000 -20000 22000
Values for Fund A should be around 14%
Values for Fund B should be around 13%
Values for Fund C should be around 21%
Values for Fund D should be around 8%
It appears that the the constructions which allow us to generate an array of returns from INDEX, i.e.:
N(IF(1,,,
or
N(INDEX(,,,
are valid in Excel but not in Google Sheets, in the latter both resolving to just a single (i.e. the first) element in the array passed.
For example, in Excel, the following:
=SUM(INDEX(A1:A10,N(IF(1,{1,2,7}))))
or:
=SUM(INDEX(A1:A10,N(INDEX({1,2,7},))))
will sum the values in A1, A2 and A7, though in Google Sheets both will sum only the value in A1.
I do not know enough about Google Sheets to know why this is the case. It may be possible to reconstruct my formula using the volatile OFFSET. I will have a look and get back to you.
Update: It appears that even an OFFSET-based solution, i.e.:
=XIRR(N(OFFSET(F2,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)-MIN(ROW(B$2:B$8))),ROW(INDIRECT("1:"&COUNTIF(B$2:B$8,J2)))),{0,1})),CHOOSE({1,2},N(OFFSET(A2,SMALL(IF(B$2:B$8=J2,ROW(B$2:B$8)-MIN(ROW(B$2:B$8))),ROW(INDIRECT("1:"&COUNTIF(B$2:B$8,J2)))),{0,1})),TODAY()))
is not possible. Again, it works fine in Excel but not in Google Sheets, for reasons similar to those given above (the arrays passed to OFFSET do not resolve as required).
I think this requires an explanation by someone well-versed in Google Sheets.
References:
https://excelxor.com/2014/09/05/index-returning-an-array-of-values/
Regards

Resources