I am wondering what is wrong with my formula
=IF(OR(AND(D2:D="New booking";R2:R != "Partner")AND(D2:D="Google Ad";AA2:AA="Yes"; R2:R != "Partner"))"Default"; S2:S)
I want it like this
IF D = New booking & R != Partner then put Default
OR
IF D = Google Ad & Conversion = Yes & R != Partner then put Default
ELSE
Put S2:S (This is all other partners)
First - you should use arrayformula if you want this formula to work on whole columns. Second - if your goal is to use single formula for whole coulmn you should be aware that AND, OR formulas don't cooperate well with arrayformula.
!= does not work in Google Sheets. Use <>
; as a separator in formulas works only in some countries. Most countries use ,
WORKING AROUND OR AND with arrayformula
You can use logical values instead. Like (D2:D="New booking")(R2:R <> "Partner") makes the same work as and(logical test1 ; logical test2). You multiply conditions. When condition is true it gives 1. When condition is false it gives 0. 01 , 10, 00 gives zero.
You can work around or function using (logical test 1)+(logical test 2) and check value. If it is 1 or more you get the same results as using OR formula.
Related
I've been trying to figure out what i'm doing wrong here when i'm doing the sumif formula's in b2,c2,d2
I have a lot going on, I realize. The data we are looking at, is between L5:U21
I have a query in a5 that pulls from l5:U that pairs any data in n5:n,p5:p,r5:r,t5:t to the selected data in the dropdown in a2. This part is working correctly for what I need.
B2 I am trying to extract from the top 3 options in the range b5:J that match a2, and add them together. Ultimately I'd like to do this if they do not have "Left" or "Right" in the J column as well.
To achieve this I pulled the data from b5:I into a sortn function seen in y5.
=SORTN(B5:I,3,,B5:B,false,D5:D,false,F5:F,false,H5:H,false)
and then my SUMIF function is as follows: =SUMIF(Z5:AF,A2,Y5:AE)
C2 is similar to B2, but I only data that matches the selection in a2, but also have "Left" in the J column.
I tried to achieve this with a similar SUMIF function i'm using in b2, but it seems to only pull the left most cell's data in the range given, not the matching column's data. So lets say if e9 = example1, it doesn't then grab the matching 2 in d9, it grabs whatever is in b9 only, and adds that. Which right now, it adds them all. I want to ultimately only pull the top 1, but I cannot even get it working correctly with all of them.
=SUMIF(J5:J,"Left",B5:H)
D2 is the same as C2, but "Right" in the J column.
This is my example / testing document I created to get a closer look at what's going on, if what i'm explaining isn't making a ton of sense.
https://docs.google.com/spreadsheets/d/1eZ7_yOrkoy_PCgcn_YxscPnDCvLXWK48JW-S7DqEgdQ/edit?usp=sharing
Try the following in C2
=QUERY({{B5:C;D5:E;F5:G},{J5:J;J5:J;J5:J}},
"select sum(Col1) where Col2='"&A2&"' and Col3='Left'
label sum(Col1) '' ",0)
For cell D2 all you need to do is use Col3='Right'
=QUERY({{B5:C;D5:E;F5:G},{J5:J;J5:J;J5:J}},
"select sum(Col1) where Col2='"&A2&"' and Col3='Right'
label sum(Col1) '' ",0)
In case you want to add more ranges like columns H-I you would adjust your formula like:
{{B5:C;D5:E;F5:G;H5:I},{J5:J;J5:J;J5:J;J5:J}}
(Do adjust the formula according to your ranges and locale)
SUGGESTION
I was experimenting earlier with SUMIFS & QUERY formulas to no success, as I also have a limited knowledge when it comes to implementing advanced Google Sheet formulas in a complex scenario. What I can suggest you try is by using a Custom Function formula in Google Sheet made possible by Google Apps Script that's integrated to the Google Sheet service.
This custom formula function will filter the range that does not contain Left or Right in column J based on the selected drop-down data, and then it returns the top 3 results in descending order.
The Custom formula Script named as CUSTOM_FUNC
/**
* Filters data in descending order from a range that doesn't contain any Left & Right based on selection in a cell dropdown selection & return the sum of the top 3 result.
*
* #param {B5:J21,A2} reference The range to be used.
* #returns The range and the cell reference to used in filtereing the data.
* #customfunction
*/
function CUSTOM_FUNC(data,dropdown_selection) {
/**Filter data that do not contain Left or Right on column J */
var lvl1 = data.map(x => {return x.toString().includes('Left') || x.toString().includes('Right') ? null : x }).filter(y => y)
/**Further filter lvl1 that matches the drop down selection*/
var res = lvl1.map(d => {
return d.map((find, index) => {return find == dropdown_selection ? d[index-1] : null}).filter(z => z)
});
/**Return the top 3 result in descending order */
return res.sort().reverse().slice(0, 3);
}
The parameters of this customer formula would be:
=CUSTOM_FUNC(data,dropdown_selection)
data
The sheet range (e.g. B5:J21) where the data you'd like to be processed resides.
dropdown_selection
The cell reference of the drop-down selection on your spreadsheet file.
To add this script in your spreadsheet file, copy and paste the script as a bound script in your Spreadsheet file by following this official guide
Demonstration
You can use the custom function formula named CUSTOM_FUNC similarly to how you use another Google Sheet formula on a cell, like this =SUM(CUSTOM_FUNC(B5:J21,A2))
Google Sheets. I want to get the next smaller value of the current value in COL A.
I've tried this...
=MAX( FILTER(INDIRECT("A" & ROW()-1 );MAX(A:A)) )
Looks good for the moment if the values in COL A are sorted.
The formula above is needed to pasted in each field.
"but", I want to use ARRAYFORMULA() ... I'm trying a long time (months) with breaks ...
That's one of my last tests.
=ArrayFormula(IF(ROW(G:G)=1;"Trip"; IF(ROW(G:G)<3;"0"; MAX( FILTER(INDIRECT("A" & ROW() );MAX(A:A)) ) ))
I've already tried VLOOKUP, too. But maybe I'm at the wrong way.
Unfortunately I didn't found a solution which match my case.
Does anybody can solve my issue? Or give me a hint to can solve this by my-self?
UPDATE Jan 26, 2021
Here we go... I've created a dummy sheet based on original values but cut not needed cols.
https://docs.google.com/spreadsheets/d/1yI0UEdZ3aKU03ElPchUuAPcmnAoMmCyXWhZBcu2Hv3g/edit#gid=0
Col A - is the "current value"
Col G+H - are some tries with ArrF
Col J - is working but not with ArrF - Shows the diff to the last value. Yes this can also be done without INDIRECT() and Co. But I want to try the basic logic.
Col K - show the last value.
Currently Col A is sorted. But if not the diff isn't working. I have added some values from above (grey marked) to simulate.
The goal should be to get the next smaller value of "current" COL A using ArrayFormula.
Use OFFSET
See the docs: OFFSET
=
{
"Last";
0;
ArrayFormula( OFFSET(A3:A, -1, 0) )
}
=
{
"Diff";
0;
ArrayFormula( A3:A100 - OFFSET(A3:A100, -1, 0) )
}
I changed the structure slightly so that it would be contained within arrays. That way you don't need the IF statements for the headers, for example.
I also did not use the whole column notation A:A partly because the array already has A1 and A2 covered. I tried A3:A but that didn't work for the diff column, because it always says it needs more rows. Probably because it needs to reference a row that is not on the same row, if that makes sense.
Refs
Arrays
OFFSET
UPDATE
Due to international settings you may need to have your functions written in this way:
=
{
"Last";
0;
ArrayFormula( OFFSET(A3:A; -1; 0) )
}
=
{
"Diff";
0;
ArrayFormula( A3:A100 - OFFSET(A3:A100; -1; 0) )
}
I have a column which won't sum? it sits beside a column with an array formula how is a sum done in this case?
This is my formula in C3:
ArrayFormula(query({M8Report!A2:T,arrayformula(left(regexreplace(M8Report!N2:N, "\n|\r", ""),150))},"Select Col5,Col2,Col1,Col21,Col3 Where (Col4 = 'Work Order') order by Col5", -1))
in B I have entered integer values in B1 I have =sum(B3:B) and the result is always 0 if instead in B1 I use B3+B4+B5+etc.. I get the correct result...
..Tried everything I can think of and same issue sum =0
since C is dynamic I need a way to sum all of the values in B
..any ideas would be helpful
In your sample sheet your formula is:
= { QUERY ; { "TOTAL" , SUM(B3:B) } }
Change it to:
=CONCAT("TOTAL ", SUM(B3:B))
The error has to do with your use of the {}, which is used to define an array literal. You just want to have 2 strings merged where one is the sum of the values. Also note that you may want to use B4:B instead since B3 is a header for the data below that.
Last, make sure the data is Numbers. The original data is formatted as Plain Text so SUM() has nothing to add.
to ditch formatting issues you can do:
={"Total", SUMPRODUCT(B5:B)}
I realize that there are multiple questions with this title, but I don't understand the answers to them, or it is not directly related to my issue.
I'm trying to avoid manually "dragging" a formula to duplicate it for each row.
Formula looks like this
=IF(ISBLANK(A6),
"",
COUNT(FILTER(Data!C$2:C,
Data!A$2:A = A6,
Data!B$2:B >= B$2,
Data!B$2:B <= B$3,
Data!C$2:C >= E$3,
Data!C$2:C <= E$2)))
I'm not sure all the anchors are needed when using ARRAYFORMULA.
The A column is the one I want to "interate", the rest of the ranges should evaluate to whatever they're evaluating to now.
I have tried this:
=ARRAYFORMULA(IF(ISBLANK(A6:A),
"",
COUNT(FILTER(Data!C$2:C,
Data!A$2:A = A6:A,
Data!B$2:B >= B$2,
Data!B$2:B <= B$3,
Data!C$2:C >= E$3,
Data!C$2:C <= E$2))))
In which the A6:A seems to evaluate correctly to each cell in the A column. However, the ranges from the Data sheet also seem to evaluate to a single value and not the ranges.
Am I missing something or do I not understand how ARRAYFORMULA works?
filter is an arrayformula by itself → it can't be used in another arrayFormula because Sheets cannot handle array of arrays.
Workaround
You are looking for countifs arrayFormula, which is solved with mmult:
=arrayformula(TRANSPOSE(MMULT(TRANSPOSE((Data!B$2:B>=B2)*(Data!B$2:B<=B3)*(Data!C$2:C<=E2)*(Data!C$2:C>=E3)),--(Data!A$2:A=TRANSPOSE(A6:A10)))))
Explanation
=arrayformula(TRANSPOSE(MMULT(...,...)
^^^^^ mmult will count for 1's and 0's in intersection
of conditions
...TRANSPOSE((Data!B$2:B>=B2)*(Data!B$2:B<=B3)*(Data!C$2:C<=E2)*(Data!C$2:C>=E3))...
^^^^ any number of 'plain' conditions goes here
...--(Data!A$2:A=TRANSPOSE(A6:A10)...
^^^^ all 'filter' conditions go here, you have only 1 of those
I am trying to do the following:
For each Row
If Cell A contains text "abc" then get value on column B and
if value on Column B is > than 0:03:00 return 0.9
else if value on Column B is < 0:03:00 and > 00:01:00 return 0.6
else return 0.3
Sum the returned value with all the others.
The result should be something like:
=IF(ISNUMBER(FIND("abc",INDIRECT(""&$A16&""&"!$D$2:$D"))),IF(INDIRECT(""&$A16&""&"!$D$2:$D")>"00:0300,???,???),?etc??)
??? are the missing parts. Also, INDIRECT() could be removed for testing, but the problem is that ??? part. I have no idea how to get the result of the IF statement and how to process it. I suppose I don't understand how to work with columns.
You could possibly use an "array formula" with LOOKUP like this in excel
=SUM(IF(ISNUMBER(FIND("abc",A2:A100)),LOOKUP(B2:B100,{0,1,3}/1440,{3,6,9}/10)))
confirmed with CTRL+SHIFT+ENTER
or this version with IFs [edited]
=SUM(IF(ISNUMBER(FIND("abc",A2:A100)),IF(B2:B100>="0:03"+0,0.9,IF(B2:B100>"0:01"+0,0.6,0.3))))
In Google spreadsheets use this version
=arrayformula(SUM(IF(ISNUMBER(FIND(ʺabcʺ,A2:A100)),IF(B2:B100>=ʺ0:03ʺ+0,0.9,IF(B2:B100>ʺ0:01ʺ+0,0.6,0.3)))))
That will add 0.3 for the total for every row where "abc" is found in the text in column A and column B is >=0 but < 0:01, 0.6. where B >=0:01 and < 0:03 and 0:09 if B >= 0:09
Using LOOKUP makes it easier to avoid multiple IFs but I'm not sure if it gives the correct values for you on the boundaries, that's more easily adjustable with the second version. You can adjust the range lengths and add INDIRECT if required.
Note: using FIND for the first condition means that the formula will look for "abc" (case-sensitive) anywhere in the text, if you only want to check for exactly "abc" with no other text you can use just range = "abc" [not case-sensitive] or EXACT(range "abc") [case-sensitive]