SUMIF cell has positive number, IF cell contains '0' return result of another cell - date

I have a Google Sheets that is calculating date values. I would like to enter a formula that decreases the date pulled from a given cell if the cell contains a positive number. However, if the cell contains a zero, I would like it to simply return the value of a cell.
Example:
Col A:
A1: 01/01/2018
A2: 01/01/2018
A3: 01/01/2018
Col B:
B1: 0
B2: 1
B3: 2
Col C:
C1: Return Value of A1 (01/01/2018)
C2: Return Value SUM(A2+B2) (01/02/2018)
C3: Return Value SUM(A3+B3) (01/03/2018)

Please try automatically updated formula:
=ARRAYFORMULA(A1:A10+B1:B10)
Notes:
change ranges to yours
you may modify the formula to get dynamic ranges: =filter(A:A+B:B,A:A>0)

This seems relatively straight forward based on your example? See this google sheet... you just add the date to column b? get the outcome you specified? I'm not sure why you should need an Array as Max has done, but this seems to give the same result: =B1+A1
I did notice that you mentioned DECREASE the date. In that case, wouldn't you just subtract the date based on an if statement? I did that in row 20 with this formula: =if(B20>0,A20-B20,A20)

Related

Match if date is within date range google sheets

I have two columns with a start (column B) and end (column C) date range, and a cell (G1) with a date.
I want to be able to look at columns B and C and return true if G1 falls in between any of the date range of B and C, and if G1 is not within the date, return false.
Any suggestions on how to do this?
You can use the following formula
=IFERROR(IF(
QUERY(L2:M14,"WHERE L <= DATE '"&TEXT(K2, "yyyy-mm-dd")&"'
AND M >= DATE '"&TEXT(K2, "yyyy-mm-dd")&"'")
>0,TRUE),FALSE)
(Please adjust ranges to your needs)
Functions used:
QUERY
Assuming this formula is used on row 2, this will work:
=ISBETWEEN($G$1,$B2,$C2)
Change $B2 and $C2 appropriately if you're not on row 2.
Note that the ISBETWEEN() function has two additional optional boolean parameters to control whether the start/end dates are inclusive or exclusive for the range; both default to TRUE for inclusive endpoints.

Postgres: How to increment the index (pointer) to access other rows

I have been trying to understand how to increment the reference to some value.
In C I would simply increment the pointer to retrieve a value in the next array location.
How does this mechanism work in Postgres? is it possible?
For an example, I have created a table with some data in:
create table mathtest (
x int, y int, val int)
insert into mathtest (x,y,val)
values (1,1,10),(2,2,20),(3,3,30),(4,4,40),(5,5,50),(6,6,60),(7,7,70),(8,8,80),(9,9,90),(10,10,100),(11,11,110)
What I want to do is add the val value from the current row and then the val value when the x value in the row equals the current x value plus 2, and then plus 4. I realise that I can't assume the next row that is retrieved will be in a set order so I can't use 'lead'
If it was C I would simply increment the pointer.
The data output needs to be when the modulo of x and y = 0 for certain divisors. (this bit works)
select
x base,
(x+2) plus1x,
(x+4) plus2x,
y,
val
from mathtest
where x%2 =0 and y%3 = 0
This outputs the following:
base plus1x plus2x y val
1 6 8 10 6 60
The output I would like is:
60 + 80 +100 = 240
I can't conceptualise how to do it. My mind seems to be stuck in procedural C mode!
Whatever I type and try is an error.
Can any body help me to get over this hurdle?
Welcome to the world of window functions.
You need an explicit ordering, otherwise it makes no sense to speak of the "previous row".
As a simple example, to get the difference to the previous value, you can query like
SELECT val -
lag(val) OVER (ORDER BY x)
FROM mathtest;

Calculating dates in excel

I want to count the dates. 1 date = 1, 2 dates = 2...
I have 2 dates and I want to prepare a formula if I have 2 dates, then this is total 2.
Adjust the range references to suit your data.
=COUNTA(C2:G2)
Where C2:G2 is your first row under datum. This equation will count the number of non blank cells.
If 4.9. is a number an not text, then you could also use
=COUNT(C2:G2)
In Excel you could create a new column that checks if the cell is a date by doing =ISERROR(DAY(A1)).
If it is a date the formula will return FALSE.
Then simply count all the cells with FALSE by doing =COUNTIF(B1:B10;FALSE)
Here B1:B10 should be replaced with the cellrange of your new column that holds the true or false values

What are tuples and lists?

I was watching Stanford - Developing iOS 9 Apps with Swift - 3. More Swift and Foundation Framework on youtube was talking about tuples and lists and i'm not sure what they are even if i searched online i still can't understand what they are.
Turple is basically a group of variables, while a list is an index of a few values of the same type.
Tuple
Tuples are really cool (I think). It lets you basically put a bunch of variables together and put a name to them or nothing.
For example, let's say you have the quadratic formula. It would make sense to group these values:
var quadraticFunction: (a: Int, b: Int, c: Int, plus: Double, minus: Double)
With this you can even return the tuple. To take this further, you might want to make a function that performs the quadratic formula by taking 1 number and adding 1 for b and 2 for c.
func performQuadraticFormula(startValue: Int) -> (a: Int, b: Int, c: Int, plus: Double, minus: Double) {
var returnQuadratic: (a: Int, b: Int, c: Int, plus: Double, minus: Double)
returnQuadratic.a = startValue
returnQuadratic.b = startValue + 1
returnQuadratic.c = startValue + 2
returnQuadratic.plus = /* lots of math for this part */
returnQuadratic.minus = /* lots of math for this part */
return returnQuadratic
}
So now you can take this output and actually store it for use later:
let function = performQuadraticFormula(startValue: 10)
print(function.a)
// you can do whatever you want with this output now
So you can assign names to these values, store them for later, assign them, return them in a function. Also, you don't have to have a name for each value, in which case it would be like this:
function.0
Lists
I guess I can see how you can easily get confused with a list and a tuple. Both can be referenced with the index of it (tuple.0, list[0]). But lists are pretty different. First off, you cannot assign names for each value. The real big difference though, is a tuple is predefined with its values while a list can expand and remove items easily.
For example, you can store a few tests grades in a list
var tests = [100, 100, 90, 78, 100, 10]
Then, next week go and add a new one and it will automatically expand:
tests.append(99.8)
A tuple migght only have 3 values and that's it; you would have to go back and add a new variable in order to add a new value. For a list you have a bunch of the same type and can add whatever you want. To get one you can do this:
let firstTest = tests[0]
Also, a list (Array) has many functions that come with it like .map(), filter(), etc. Tuple does not have that.
Think of a list of a group of statistics or data and a tuple as just a way to put a bunch of variables on one line
A tuple is a group of zero or more values represented as one value.
For example ("John", "Smith") holds the first and last name of a person. You can access the inner values using the dot(.) notation followed by the index of the value:
var person = ("John", "Smith")
var firstName = person.0 // John
var lastName = person.1 // Smith
An array literal is written as a list of values, separated by commas, surrounded by a pair of square brackets:
The example below creates an array called shoppingList to store String values:
var shoppingList: [String] = ["Eggs", "Milk"]
// shoppingList has been initialized with two initial items
var firstItem = shoppingList[0]
// firstItem is equal to "Eggs"

SSRS Expression works as cell value expression, but not as background color value expression

I have an SSRS report with a matrix in it, where I needed to display the Growth Percentage in a column group compared to the previous column value. I managed this by using custom code...
DIM PreviousColValue AS Decimal
Dim RowName AS String = ""
Public Function GetPreviousColValue(byval Val as Decimal, byval rwName as string) as Decimal
DIM Local_PreviousColValue AS Decimal
IF RowName <> rwName THEN
RowName = rwName
PreviousColValue = val
Local_PreviousColValue = 0
ELSE
Local_PreviousColValue = (Val - PreviousColValue)/PreviousColValue
PreviousColValue = val
END IF
Return Local_PreviousColValue
End Function
..and then using this as the value expression in the cell..
=Round(Code.GetPreviousColValue(ReportItems!Textbox8.Value,Fields!BusinessUnit.Value)*100,0,system.MidpointRounding.AwayFromZero)
So far so good, this produces the expected value. Now I need to use this expression in a background color expression to get a red/yellow/green but in that capacity it fails.
The background color expression looks like this: =IIF(ROUND(Code.GetPreviousColValue(ReportItems!Textbox9.Value,Fields!Salesperson.Value)*100,0,System.MidpointRounding.AwayFromZero)<=-5,"Red"
,IIF(ROUND(Code.GetPreviousColValue(ReportItems!Textbox9.Value,Fields!Salesperson.Value)*100,0,System.MidpointRounding.AwayFromZero) >=5,"Green"
,"Yellow"))
When I run the report the background color expression only ever returns yellow. As a test I pasted the background color expression in as the cell value and ran it again. Results in the image below
I get no build or run time errors so I'm not sure why this does not work.
After some more searching I found a better Custom Code solution than what I was using to get the Growth Percentage in a column group compared to the previous column value. Besides being simpler to read this version has an added benefit: You can dynamically hide the growth percentage column for your first instance of the column group (because it will always be zero or null) and still get the right values in the 2nd/3rd/4th instance of the column group.
Public Function GetDeltaPercentage(ByVal PreviousValue, ByVal CurrentValue) As Object
If IsNothing(PreviousValue) OR IsNothing(CurrentValue) Then
Return Nothing
Else if PreviousValue = 0 OR CurrentValue = 0 Then
Return Nothing
Else
Return (CurrentValue - PreviousValue) / PreviousValue
End If
End Function
The new function is called like so
=Code.GetDeltaPercentage(Previous(Sum(<expression or dataset field>),"Group ByColumn"), Sum(<expression or dataset field>))
Re: the original question - why does my cell value expression not work when used as the background color expression - I took an easy out and just referenced the cell value.
=IIF(ROUND(Me.Value*100,0,System.MidpointRounding.AwayFromZero)<=-5,"Red"
,IIF(ROUND(Me.Value*100,0,System.MidpointRounding.AwayFromZero) >=5,"Green"
,"Yellow"))