I’m trying to add three new columns into a report I’ve already created. I’d like to sum up the item quantities by their age. So, the first column would be the total quantity for each item for the last 0-7 days, second would be for the last 7-14 days and the last would be +14 days.
This is what I have currently:
=IIF(Fields!Date.Value >= DATEADD(DateInterval.Day, -7, FormatDateTime(Today)), SUM(Fields!Qty.Value))
I’ve tried modifying this in several ways but all (including the expression above) are underlined in red indicating that there is an error.
I’ve tried:
= IIF(Fields!Date.Value >= DATEADD(DateInterval.Day, -7, Now()), SUM(Fields!Qty.Value))
= IIF(Format(Fields!Date.Value, “dd/mm/yyyy”) >= DATEADD(DateInterval.Day, -7, Format(Today(), “dd/mm/yyyy”)), SUM(Fields!Qty.Value))
I’m at a loss as I don’t really write expressions too often. Am I going about this the wrong way?
The issue with your IIF is that there isn't an ELSE condition after the SUM. The IIF will return the value if the condition is true and the if not.
IIF(< condition >, < true >, < false >)
Also you want the sum to be outside the IIF in this instance, otherwise it will check the first date and if it matches add all the quantities from all dates.
=SUM(IIF(Fields!Date.Value >= TODAY.AddDays(-7), Fields!Qty.Value, 0))
If the Qty field is a decimal, the 0 may need conversion with CDEC(0).
Related
I'm working on trying to add an array formula so that the status column updates as information is entered.
This is an order tracking sheet. When an order is entered get set to Available, Once a driver is assigned change the status to Dispatched. As times are entered in the In and Out columns to change from Picked to Delivered. Finally once its checked off as Billed to mark the status as Complete.
So far I've only gotten to
=ARRAYFORMULA(IF(LEN(D3:D&H3:H&I3:I&M3:M&N3:N)=0, "Available", IF(D3:D<>"", "Dispatched")))
I haven't been able to figure out past that.
https://docs.google.com/spreadsheets/d/13tOkLwtPYyWm9rUfkCidqwUygzFfVfmIzV-EwL5i7hM/edit?usp=sharing
I wasn't sure which column was used to mark billed, so I just guess column P, just change it to the proper column. Enter this formula in row 1 of your status column.
={"Status";
ARRAYFORMULA(
IFERROR(
IFS(
P2:P<>"", "Complete",
J2:J<>"", "Delivered",
I2:I<>"", "Picked",
E2:E<>"", "Dispatched"
),
"")
)}
Explanation
Starting inside and working out:
The ranges J2:J, etc, tell the array formula which column to evaluate as it goes row by row, starting at row 2, and ending at the bottom of the sheet.
The IFS formula checks condition:result pairs, If the first condition is met, it displays that value, but if not, it goes to the next one, and so on until it finds a condition that is true or reaches the end.
The IFS formula will return an error if it doesn't find any of the conditions to be true, so the IFERROR says to leave the cell blank if there are no true conditions.
The ARRAYFORMULA evaluates each row for the defined range.
The { xxxx ; xxxxxxx}stacks the items after the semicolon below the item before the semicolon. In this usage, the label "Status" is in row 1, and the results are in the rows below it. This ensures that no one accidentally sorts or erases the formula.
I have a question (again :)). let assume we have the following data:
the first number is the day second the month and third the event
day(1,1, 'New Year')
day(1,1, 'The day after the new year')
day(23,1, 'The day i will finally understand this language :)')
day(14,2, 'Valentin's day')
day(16,2, 'Family day')
day(22,2, 'hein.. dont now lol')
nday(1,31).
nday(2,28).
nday(3,31).
nday(4,30).
nday(5,31).
I'm asked to create a predicate such that given a Day, it returns a month (only if the given day do not have event. for instance freeDay(23,X). X should have the value 2. if X equals 4, it should holds 1 (and if we enter the semi colon, it will return 2 since day 4 doesn't have any event in February as well. i have many more data. So i did the following but i get the value 0.
freeDay(_, Month,0):- Month > 12, !.
freeDay(X,Answer):- freeDay(X, 1, Answer).
freeDay(Day, Month,X):-
day(Day, Month,_),
W is Month + 1,
freeDay(Day, W, X).
freeDay(Day, Month, X):-
W is Month +1,
freeDay(Day,W, X).
Can you tell me what i did wrong please??
What your code does:
By calling freeDay(23,X), freeDay(X,Answer) succeds which calls the freeDay(X, 1, Answer).
Prolog first checks which of the predicates can be executed with the current inputs.
It finds out that freeDay(_, Month,0):- Month > 12, !. is not applicable since the month is 1 and it moves to the next predicate.
freeDay(Day, Month,X) is applicable, and what it does is increasing the month and calling itself(recursion).
The month keeps increasing when finally is more than 12. Remember everytime a predicate is called prolog checks the first predicate that it is applicable. Therefore this time freeDay(_, Month,0):- Month > 12, ! succeeds.
freeDay(_, Month,0):- Month > 12, !. breaks the loop (recursion) by the use of the cut annotation ! and returns the Answer which is 0 in this case. (In plain english here you say no matter what day is if month is greater than 12 return 0. This is the last statement executed.)
I hope you understand what's wrong. Generally logic programming requires thinking outside of the box. You need first to understand the problem and then attempt to solve it, in a simplistic way.
Using Oracle 11gR2 Expression Edition.
My data looks like following
ordertype
---------
ZOCO
ZOSA
ZOST
We are trying to find out records where the column is not between a certain range of values.
If I run a query with <= and >= operators:
SELECT * FROM table where ordertype <= 'ZAAA' OR ordertype >= 'ZZZZ';
then I get 0 results. This is the right answer.
However, if I use NOT BETWEEN:
SELECT * FROM table where ordertype NOT BETWEEN 'ZAAA' AND 'ZZZZ';
, then it gives multiple hits.
My understanding is that both syntax should give the same result but they are not. What am I missing? Reason I want to use NOT BETWEEN because a lot of our existing code already has this syntax and I do not want to change it without understanding the reasons.
Thank you.
Thanks for all those who posted. I ran the queries again and after fixing the "OR" in the first query, the results are the same. I still have the question of why Oracle character sorting is not recognizing it as expected, but my question which is about difference between NOT BETWEEN and <> was a false alarm. I apologize for confusion.
SELECT * FROM table where ordertype <= 'ZAAA' AND ordertype >= 'ZZZZ';
No string can be <= 'ZAAA' and >= 'ZZZZ'.
You need to use a disjunction instead:
SELECT * FROM table where ordertype < 'ZAAA' OR ordertype > 'ZZZZ';
BTW, given that BETWEEN is inclusive, NOT BETWEEN is exclusive
This is a common pitfall. you have to remember the De Morgan's Laws:
not (A and B) is the same as (not A) or (not B)
Feel free to experiment with this simple live example to convince yourself that those results are quite coherent: http://sqlfiddle.com/#!4/d41d8/38326
That being said, the only way (I can see) for the string like ZOCO for not being between ZAAA and ZZZZ would be:
having some hidden character just behind the Z (i.e.: 'Z'||CHR(0)||'OCO')
or using a locale such as Z-something is actually considered as a different letter, with a collation order outside of the given range. I don't know if such locale exists, but for example, in Welch, LL is considered as a single letter that should be sorted after the plain L. See http://en.wikipedia.org/wiki/Alphabetical_order#Language-specific_conventions
or having homogplyphs such as 0, 𐒠 or О instead of O in your data.
If it's not between the values, it has to be either < OR >, not AND.
In the first query, you ask for the records that are at the same time less than 'ZAAA' and also greater than 'ZZZZ'. Of course, there is no such value that fullfills both requirements, hence zero records are returned.
In the second query, you ask for records, that are either less than 'ZAAA' or greater than 'ZZZZ' (ie not between those boundaries [not between...]). There is a possibility that such records exist, and as your select statement proves, there are indeed such records, that are returned by the statement.
Your understanding that both statements are same is incorrect. NOT BETWEEN is not evaluated the way you're thinking. It simply returns the results which fall outside evaluation of BETWEEN for the parameters.
IF you check Oracle documentation for BETWEEN, it says -
The value of
expr1 NOT BETWEEN expr2 AND expr3
is the value of the expression
NOT (expr1 BETWEEN expr2 AND expr3)
I have 2 expressions to fill in the column for the current amount and prior amount:
Current Amount: =IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!AP.Value, Fields!DEPR.Value, "")
Prior Amount: =IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!PRAP.Value, Fields!DEPR.Value, "")
What I need to is complete a 3rd column (called "Diff) by subtracting the value in the prior amount field from the value in the current amount field.
I tried to use the following expression that subtracts 1 from the other to get the difference:
=(=IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!AP.Value, Fields!DEPR.Value, 0)) – (=IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!PRAP.Value, Fields!DEPR.Value, 0))
However, I get the following errorm message:
The Value expression for the textrun ‘Textbox6.Paragraphs[0].TextRuns[0]’ contains an error: [BC30037] Character is not valid.
FYI, Textbox6 is the cells where this expression resides. Any help in correcting this expression would be greatly appreciated. Thanks for your help.
I think there are two Problems with your diff expression.
First i would take away some equal signs:
=IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!AP.Value, Fields!DEPR.Value, 0) – IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!PRAP.Value, Fields!DEPR.Value, 0)
The second thing is, that according to the error message your Fields seem to formatted as characters not doubles. So you will need to convert them before substracting them. You should already do this in your sql-code with:
CONVERT(Fields!DEPR.Value AS numeric)
Hope this helps
I have 2 independent but contiguous date ranges. The first range is the start and end date for a project. Lets say start = 3/21/10 and end = 5/16/10. The second range is a month boundary (say 3/1/10 to 3/31/10, 4/1/10 to 4/30/10, etc.) I need to figure out how many days in each month fall into the first range.
The answer to my example above is March = 10, April = 30, May = 16.
I am trying to figure out an excel formula or VBA function that will give me this value.
Any thoughts on an algorithm for this? I feel it should be rather easy but I can't seem to figure it out.
I have a formula which will return TRUE/FALSE if ANY part of the month range is within the project start/end but not the number of days. That function is below.
return month_start <= project_end And month_end >= project_start
Think it figured it out.
=MAX( MIN(project_end, month_end) - MAX(project_start,month_start) + 1 , 0 )