Why does a specific arrayformula not work in google sheets but works fine in excel - 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

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))

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))

Conditional formatting on the first x number of rows, regardless of filter or sort, in Excel

I'm trying to find a way to easily identify the first ten rows in a table column, no matter how it's been sorted/filtered. Is there a way to use conditional formatting to highlight these cells?
Examples of desired results...
Sample data:
product price units code
Item02 15.97 2191 7UQC
Item05 12.95 1523 TAAI
Item13 9.49 1410 LV9E
Item01 5.69 591 6DOY
Item04 15.97 554 ZCN2
Item08 10.68 451 2GN0
Item03 13.95 411 FP6A
Item07 25.45 174 PEWK
Item09 14.99 157 B5S4
Item06 18 152 XJ4G
Item10 11.45 148 BY8M
Item11 16.99 66 86C2
Item12 24.5 17 X31K
Item14 24.95 14 QJEI
When sorting by price the first 10 products highlighted differ from those in the next example.
The first 10 visible products are highlighted after filtering out Item12, Item05, and Item08.
Choosing to sort by units automatically highlights a different set of products.
Use this formula in the Conditional Formatting:
=SUBTOTAL(3,$A$2:$A2)<11
Make sure it applies to the entire dataset.
The formula returns the row number relative to the visible row number. Thus as a row is hidden the row beneath the hidden returns one greater than it would.
To see how it works place SUBTOTAL(3,$A$2:$A2) in an empty column. Then filter the table and watch as the numbers change.
The 3 refers to the COUNTA() function, which will count any non-empty cell.
Subtotal is designed to work with data that gets filtered to return only the visible data.
So the Formula will only count the visible cells that are not empty.
In the conditional formatting dialog, choose New rule -> Use a formula.... Enter =row()<=10.

Automate MIN and MAX temperatures for a certain date

I have big amount of data (60k rows) in Excel that is similar to this:
Temperature Humidity Date
20.1 68 22-dec-14
20.3 67 22-dec-14
20.4 65 22-dec-14
20.0 64 23-dec-14
20.5 64 23-dec-14
20.9 65 24-dec-14
21.4 64 24-dec-14
23.4 64 25-dec-14
23.8 65 25-dec-14
23.9 64 25-dec-14
18.4 64 25-dec-14
I created new columns outside this table that contains the individual dates and I want to extract the MAX, MIN and possibly the AVERAGE of that date
DATE MIN MAX AVG
22/Dez/14
23/Dez/14
24/Dez/14
25/Dez/14
I tried but I can't seem to find a way for Excel to work for me. Could you help me?
I suggest you try a PivotTable:
Suppose column A contains the dates, and column B the values. I've allowed 6 rows in each; extend as necessary.
Consider a sample date in $D$1. The formulas you need are:
MIN: =MIN(IF(D1=A1:A6,B1:B6,MAX(B1:B6))). (You need to enter this as an array formula).
MAX: =MAX(IF(D1=A1:A6,B1:B6,MIN(B1:B6))). (You need to enter this as an array formula).
Use AVERAGEIF out of the box.
Remember that you need to press Ctrl + Shift + Return to enter an array formula. Then it's a simple case of copying that formula downwards.
They return the minimum or maximum value of the entire sample if a given date is not present in the set, which might not be desirable. You could adjust this behaviour with a containing IF.
You can take care of the pseudo-MIN/MAX with the AGGREGATE¹ function using the 14 (LARGE) and 15 (SMALL) sub-functions together with the 6 (ignore errors) option and the AVERAGEIF function can take care of the rest.
      
The standard formulas in F2:H2 are,
=AGGREGATE(15, 6, ($A$2:$A$60000)/($C$2:$C$60000=$E2), 1)
=AGGREGATE(14, 6, ($A$2:$A$60000)/($C$2:$C$60000=$E2), 1)
=AVERAGEIF($C$2:$C$60000, $E2, $A$2:$A$60000)
Fill down as necessary. An advantage of this method is that you can get the second, third, etc smallest or largest simply by raising the 1 (k ordinal) number at the right end of the AGGREGATE formula.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

In excel, I need to find the maximum date based on the employee number

I have tried to use the following formula when trying to find the max date of these columns based on the employee number in my hundreds of thousands lines of data. The formula bar gives me 'yes' when it is the max, however in my cell it says 'no'. I cannot figure out what the issue is. Thanks for the help.
Tamara
Excel Max date formula Image
Formula used: =IF(AQ2=MAX(IF($C:$C=C2,$AQ:$AQ)),"YES","NO")
A B Employee Number Max?
11-Mar-13 12-Mar-13 199 NO
24-Mar-13 26-Mar-13 199 NO
1-Aug-13 6-Aug-13 199 NO
22-Dec-13 27-Dec-13 199 NO
15-Apr-13 17-Apr-13 206 NO
18-Apr-13 18-Apr-13 206 NO
8-Aug-13 10-Aug-13 206 NO
17-Oct-13 18-Oct-13 206 NO
25-Dec-13 20-Feb-14 206 YES
8-May-13 8-May-13 214 NO
You can also accomplish this without an array is all of the dates for a specific employee ID are unique--that is, you won't have two of the same date. In this case, the following formula will check that (a) the number of dates with employee ID is equal to (b) the number of dates with employee ID that are less than or equal to the current employee ID. This will only be true for the "max" date for said employee id:
=IF(COUNTIFS($C:$C,C2)=COUNTIFS($C:$C,C2,$A:$A,"<="&A2),"Yes","No")
If I understand your question correctly, you want to find the set of dates with the largest time span in between said dates. If this is the case, then I would recommend using two seperate fucntions, the =DAYS360 function and the =MAX function.
I have re-created your sheet and it will end up looking similar to this:
Here is the same picture of the same sheet with functions revealed, so that you can see how the functions are used:
The =DAYS360 function takes two inputs, and return the number of days in between two dates. The max function simply finds the largest number in a range. Please let me know if this helped.
EDIT: Also, if you want to see the actual word Max next to the largest date range, you can nest the Max fucntion from my column E within an If function, like this:
=IF(MAX(D:D)=D2,"Max","")
If I understand you correctly, do you want "YES" to appear for each employee's max date range? Assuming column AQ contains the spans between dates in columns A and B (i.e. =B2-A2 copied down), your formula should work.
This only works as an array formula, so make sure you press CTRL+SHIFT+ENTER when entering the formula, then copy it down to all cells in the same column.
=IF(AQ2=MAX(IF($C:$C=C2,$AQ:$AQ)),"YES","NO"), entered in D2 using CTRL+SHIFT+ENTERand copied down produces the following:
A B C D ... AQ
11-Mar-13 12-Mar-13 199 NO 1
24-Mar-13 26-Mar-13 199 NO 2
1-Aug-13 6-Aug-13 199 YES 5
22-Dec-13 27-Dec-13 199 YES 5
15-Apr-13 17-Apr-13 206 NO 2
18-Apr-13 18-Apr-13 206 NO 0
8-Aug-13 10-Aug-13 206 NO 2
17-Oct-13 18-Oct-13 206 NO 1
25-Dec-13 20-Feb-14 206 YES 57
8-May-13 8-May-13 214 YES 0
If you are simply looking for the greatest date range, the formula =IF(E2=MAX($E:$E),"YES","NO") entered in D2 and copied down will do the trick.

Resources