Bigger than X but smaller than Y - date

I've been racking my brain on Google Spreadsheets to make my conditional format rule be greater than or equal to 14 and less than or equal to 20. The current code is this
=AND(DAYS(TODAY(),DATEVALUE(F:F))>=14,D:D <> "Exiled Emperor",D:D <> "High Council", D:D <> "Dark Council",D:D <> "Darth", M:M <> "Honorary")

try:
=(DAYS(TODAY(), DATEVALUE(F:F))>=14)*
(DAYS(TODAY(), DATEVALUE(F:F))<=21)*
(NOT(REGEXMATCH(D:D, "Exiled Emperor|High Council|Dark Council|Darth")))*
(M:M<>"Honorary")

Related

TSQL divide one count by another to give a proportion

I would like to calculate the proportion of animals in column BreedTypeID with a value of 1. I think the easiest way is to count the n BreedTypeID = 1 / total BreedTypeID. (I also wnat them to have the same YearDOB and substring in their ID as shown) I tried the following:
(COUNT([dbo].[tblBreed].[BreedTypeID])=1 OVER (PARTITION BY Substring([AnimalNo],6,6), YEAR([DOB]))/ COUNT([dbo].[tblBreed].[BreedTypeID]) OVER (PARTITION BY Substring([AnimalNo],6,6), YEAR([DOB]))) As Proportion
But it bugged with the COUNT([dbo].[tblBreed].[BreedTypeID])=1
How can I specify to only count [BreedTypeID] when =1?
Many thanks
This will fix your problem, although I would suggest you use table aliases instead of schema.table.column. Much easier to read:
Just replace:
COUNT([dbo].[tblBreed].[BreedTypeID])=1
WITH
SUM( CASE WHEN [dbo].[tblBreed].[BreedTypeID] = 1 THEN 1 ELSE 0 END)

Do these two postgres expressions give same results?

I have two fields with range type.
Are these two where expressions will give same results?
where range1 && range2
where not isempty( range1 * range2 )
They will, indeed.
Both overlap operator (&&) and intersection (*) are evaluated correctly, including cases where the 2 ranges have a common bound and their intersection:
only contains 1 element (= the bound is included in both)
contains no elements (= the bound is not included in at least 1 of the 2 ranges)
The following query tests pretty much all the cases (= intersections with more than 1 point, exactly 1 point, 0 points but "close", "truly" 0 points, and all the combinations of lower/upper bounds inclusions):
WITH r(range) AS (
VALUES (numrange(0,1,'[]')), (numrange(1,2,'[]')), (numrange(0,2,'[]')), (numrange(5,6, '[]')),
(numrange(0,1,'[)')), (numrange(1,2,'[)')), (numrange(0,2,'[)')), (numrange(5,6, '[)')),
(numrange(0,1,'(]')), (numrange(1,2,'(]')), (numrange(0,2,'(]')), (numrange(5,6, '(]')),
(numrange(0,1,'()')), (numrange(1,2,'()')), (numrange(0,2,'()')), (numrange(5,6, '()'))
)
SELECT * FROM (
SELECT r1.range, r2.range, r1.range && r2.range AS UsingOverlap, NOT isempty(r1.range * r2.range) AS UsingIntersect
FROM r r1, r r2
) T
Feel free to add WHERE UsingOverlap <> UsingIntersect.

how to calculate total balance per state per country using accumulate function in openedge

I have tried the code.
DEFINE VARIABLE totalbalance AS DECIMAL NO-UNDO.
DEFINE FRAME f1
WITH CENTERED THREE-D SIZE 100 BY 50.
FOR EACH customer NO-LOCK BREAK BY country WITH FRAME f1:
ACCUMULATE balance(TOTAL BY country).
IF FIRST-OF(customer.country) THEN
DISPLAY customer.country.
DISPLAY customer.state customer.balance.
IF LAST-OF(customer.country) THEN
DO:
DISPLAY SKIP FILL("-", 25) AT 50 FORMAT "x(25)".
DISPLAY ACCUM TOTAL customer.balance AT 51.
DISPLAY SKIP FILL("-", 25) AT 50 FORMAT "x(25)".
END.
END.
It only gives total balance per country but I also want to display total balance per state.
You do not have a "break by state" so it will do nothing by state.
Something like this (not very tested):
define frame f1
with
centered
.
for each customer no-lock break by country by state with frame f1:
accumulate balance( total by country ).
accumulate balance( sub-total by state ).
if first-of( customer.country ) then
display customer.country.
if first-of( customer.state ) then
display customer.state.
display customer.balance.
if last-of( customer.country ) then
do:
display skip fill( "-", 25 ) at 50 format "x(25)".
display accum total customer.balance at 51.
display skip fill( "-", 25 ) at 50 format "x(25)".
end.
if last-of( customer.state ) then
do:
display skip fill( "-", 25 ) at 80 format "x(25)".
display accum sub-total customer.balance at 81.
display skip fill( "-", 25 ) at 80 format "x(25)".
end.
end.
(That probably doesn't actually work... but the multiple BY clauses are the main thing that you are missing.)
Personally I find the ACCUM syntax to be unpleasant and not worth bothering with. I usually just create and manage simple variables. I find that sort of coding to be much cleaner. So unless this is a "gotchya" question on a skills test I strongly suggest that you avoid coding in this manner. If it is a "gotchya" question move on to a more suitable prospective employer -- you don't want to work for anyone who thinks that this is a good idea.
I would do it more like this:
define variable countryBalance as decimal no-undo.
define variable stateBalance as decimal no-undo.
for each customer no-lock break by country by state with frame f1:
if first-of( customer.country ) then
do:
display customer.country.
countryBalance = 0.
end.
if first-of( customer.state ) then
do:
display customer.state.
statebalance = 0.
end.
assign
countryBalance = countryBalance + customer.balance
stateBalance = stateBalance + customer.balance
.
display customer.balance.
if last-of( customer.country ) then
do:
display countryBalance.
end.
if last-of( customer.state ) then
do:
display stateBalance.
end.
end.
I think that is a whole lot easier to read, understand and maintain.

cross-tab conditional formatting based on column

I have a cross-tab in crystal reports with column representing transport line, rows showing dates and summary field representing TEU (its just numerical value). So I have something like this:
L1 L2 L3 TOTAL
D1 10 5 0 15
D2 1 3 5 9
D3 3 50 17 70
Now I'd like to conditionally put background to the summary (numerical) field, but the condition depends also on the line. So in theory, after clicking on the summary field->format field->background->formula I'd put something like this:
select {#Line}
case "L1": (if currentfieldvalue >5 then crGreen else crRed)
case "L2": (if currentfieldvalue >10 then crGreen else crYellow)
case "L3": (if currentfieldvalue <8 then crBlue else crNoColor)
but for some reasons those conditions are completely ignored. I've even tried something as simple as
if {#Line} ="L1" then crGreen
but as above, crystal 2011 (14.06) ignores it.
Got it finally using GridRowColumnValue ("#Line"):
select GridRowColumnValue ("#Line")
case "L1": (if currentfieldvalue >5 then crGreen else crRed)
case "L2": (if currentfieldvalue >10 then crGreen else crYellow)
case "L3": (if currentfieldvalue <8 then crBlue else crNoColor)
Source: http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=6798

T-SQL: How to make a positive value turn into the equivalent negative value (e.g "10.00" to "-10.00"

Ok so i have a DECIMAL field called "Score". (e.g 10.00)
Now, in my SP, i want to increment/decrement the value of this field in update transactions.
So i might want to do this:
SET #NewScore = #CurrentScore + #Points
Where #Points is the value im going to increment/decrement.
Now lets say #Points = 10.00.
In a certain scenario, i want 10.00 to become -10.00
So the statement would be translated to:
SET #NewScore = #CurrentScore + -10.00
How can i do that?
I know its a strange question, but basically i want that statement to be dynamic, in that i dont want to have a different statement for incrementing/decrementing the value.
I just want something like this:
SET #Points = 10.00
IF #ActivityBeingPerformedIsFoo
BEGIN
-- SET #Points to be equivalent negative value, (e.g -10.00)
END
SET #NewScore = #CurrentScore + #Points
Can't you just multiply it by -1?
I always do 0 - #Points. It was this way in some code I inherited. "A foolish consistency..."
Multiply #Points by -1 in that certain scenario.
I thought of subtracting it with a multiple of 2, i.e. x - 2x