Mismatch Range error on using IFs in sheets - if-statement

I am using the formula below and getting an error "IFS has mismatched range sizes. Expected row count: 1. column count: 1. Actual row count: 2, column count: 2."
The code is to ignore Sat/Sun and pick High values of Thurs/Fri in case of Sat/Sun.
$c$1 is the present date.
Can someone help me debug this
=ifs(weekday($C$1-1,2)=6,GOOGLEFINANCE($S$1,"high",today()-(today()-$C$1+4)),weekday($C$1-1,2)=7,GOOGLEFINANCE($S$1,"high",today()-(today()-$C$1+4)))

Issue:
IFS syntax is:
IFS(condition1,value1,condition2,value2,...)
It's important to realize all arguments should be of the same size. Same rows and columns. If there's a mismatch, this error is thrown
Expected row count: 1. column count: 1. Actual row count: 2, column count: 2.
What this says is, 1x1 array is expected, but instead the function got 2x2 array and it doesn't know what to do with that.
In this specific case, GOOGLEFINANCE returns a 2x2 array with it's headers, while WEEKDAY returns a 1x1 array.
Solution:
Either increase the 1x1 array to 2x2 array or reduce the 2x2 array to 1x1 array. Increasing can be done with array operations like ARRAYFORMULA(IF()) or IF(SEQUENCE()). Decreasing can be done with INDEX/QUERY or FILTER
Snippet:
=ifs(weekday($C$1-1,2)=6,INDEX(GOOGLEFINANCE($S$1,"high",today()-(today()-$C$1+4)),2,2),weekday($C$1-1,2)=7,INDEX(GOOGLEFINANCE($S$1,"high",today()-(today()-$C$1+4)),2,2))

try:
=INDEX(IF(WEEKDAY($C$1-1,2)=6,
GOOGLEFINANCE($S$1,"high",TODAY()-(TODAY()-$C$1+4)),
IF(WEEKDAY($C$1-1,2)=7,
GOOGLEFINANCE($S$1,"high",TODAY()-(TODAY()-$C$1+4)), )), 2, 2)
reason why your IFS wont work: https://webapps.stackexchange.com/a/124685/186471

Related

#N/A error stating only 1 argument, but IF formula seems to be set up correctly?

Formula causing error:
=IF(ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2)="",0,ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2))))
The goal is to survey the columns listed for Row 2, which themselves subtract two dates to get the days between the two. As some of these dates are empty (it's a huge data range) I had to build in an argument to show a blank so as not to skew the average output.
The problem is the cell is showing #N/A:
Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 1 arguments.
try:
=IF(ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2))="",0,
ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2)))
or:
=IF(IFERROR(ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2)))="",0,
ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2)))
or:
=IFERROR(ROUND(AVERAGE($I2,$L2,$O2,$R2,$V2,$X2,$V2)), 0)

Count if value is lower than 80 and equal or bigger than 0 but not empty

I'm trying to countif some values but not the empty ones this is my formula and this is the data that I try to count:
=COUNTIF(B2:B15,"<0.8, >=0")
But this formula counts the empty one too, I would like to have only one like in the image in colum b should be count only 2 but it count 13.
Try
=COUNTIFS(B2:B15,"<0.8",B2:B15,">0")
COUNTIFS
or
=SUMPRODUCT((B2:B15<0.8)*(B2:B15>0))
SUMRPODUCT

What is the data type returned for an IF function (SharePoint Calculated Column)?

I have a rather long calculated column which uses the drop-downs of two other columns to return a 'score' based on their values.
A section of it looks like this:
IF(AND([Current Impact]="High",[Current Probability]="Low"),17)
This would return the value 17 if the impact is high and the probability is low in those other columns.
This seems to return the 17 as a string rather than a number because sorting on my calculated column (score) from high to low produces a result sorted on the first digit e.g. 5, 4, 32, 2, 18
I have a workaround to this - I enclose the whole formula in a (an?) =value() function.
However, I'm curious as to why the IF function returns the string data types instead of a number?
As far as I know, in the column settings you could specify what data type returned from the calculated formula:

How to count a value in a range using array formula

I want to count the number of No in theses ranges F:R,BC:BN,CX:DI with array formula so if any one submit a new response containing No in these ranges it counts them
I tried using this formula
=ARRAYFORMULA(IF(ROW(E:E)=1,"NC",IF(LEN(E:E), IF(IFERROR(REGEXEXTRACT(TRANSPOSE(QUERY(TRANSPOSE(COUNTIFS(OR(DV:EG="No",BW:CH="No",U:AG="No"))),, 999^99)), "♦"))="♦", 1, 0), )))
but it didn't work, I also tried this formula:
=ARRAYFORMULA(IF(ROW(A:A)=1,"NC",IF(LEN(A:A)=0,IFERROR(1/0),COUNTIFS(F:R,"No")+COUNTIFS(BC:BN,"No")+COUNTIFS(CX:DI,"No"))))
But it counted all the value in the whole range
I need it to count the No row by row so at the end of every row under NC it shows the number of the No in these ranges F:R,BC:BN,CX:DI
Here is a spread sheet containing the data
https://docs.google.com/spreadsheets/d/1SksZv0h82j5oEZBj2AN5anDFr80AYNR5ettSwkpUKys/edit#gid=0
=ARRAYFORMULA({"NC"; IF(LEN(A2:A),
MMULT(IFERROR(LEN(REGEXEXTRACT({F2:R,BC2:BN,CX2:DI}, "No"))/
LEN(REGEXEXTRACT({F2:R,BC2:BN,CX2:DI}, "No")), 0),
TRANSPOSE(COLUMN(A1:AK1)^0)), )})

How to use the dimension of a python matrix in a loop

I am working with a matrix, lets call it X, in python.
I know how to get the dimension of the matrix using X.shape but I am interested specially on using the number of rows of the matrix in a for loop, and I dont know how to get this value in a datatype suitable for a loop.
For example, imagine tihs simple situation:
a = np.matrix([[1,2,3],[4,5,6]])
for i in 1:(number of rows of a)
print i
How can I get automatically that "number of rows of a"?
X.shape[0] == number of rows in X
A superficial search on numpy will lead you to shape. It returns a tuple of array dimensions.
In your case, the first dimension (axe) concerns the columns. You can access it as you access a tuple's element:
import numpy as np
a = np.matrix([[1,2,3],[4,5,6]])
# a. shape[1]: columns
for i in range(0,a.shape[1]):
print 'column '+format(i)
# a. shape[0]: rows
for i in range(0, a.shape[0]):
print 'row '+format(i)
This will print:
column 0
column 1
column 2
row 0
row 1