Nested IIF or SWITCH Statement syntax needed correctly - syntax

Can somebody please tell me what I am missing in this formula in SSRS? Or better yet can somebody please write this same thing in a NESTED IIF syntax?
Switch(
(Parameters!StartMonth.Value <= 1 And Parameters!EndMonth.Value >= 1),
(Code.CalculateFraction(
(Fields!retail1.Value -Fields!cost1.Value) , Fields!cost1.Value
) *100
),
(Parameters!StartMonth.Value <= 2 And Parameters!EndMonth.Value >= 2),
(Code.CalculateFraction(
(
(Fields!retail1.Value +Fields!retail2.Value)-
(Fields!cost1.Value + Fields!cost2.Value)
) ,
(Fields!cost1.Value + Fields!cost2.Value)
) *100
)
)
This is seriously driving me crazy. For simplicity I have just put 2 iterations here. I have 12 of these and every next step I have to sum up retail1 until retail12 and cost1 until cost12.
I cant get it right for these two in the first place.
EDIT:
I am trying this now and still returns the value in the first condition
=iif(
Parameters!StartMonth.Value <= 1 AND Parameters!EndMonth.Value >= 1,
ReportItems!txtTotal2.Value,
iif(
Parameters!StartMonth.Value <= 2 AND Parameters!EndMonth.Value >= 2,
ReportItems!txtTotal3.Value,
iif(
Parameters!StartMonth.Value <= 3 AND Parameters!EndMonth.Value >= 3,
ReportItems!txtTotal4.Value,
Nothing
)
)
)
EDIT 2:
FIGURED OUT WHAT WAS INCORRECT.
My entire logic was incorrect to get to the result that I was expecting. It was obvious in my case that whatever I use, be it IIF or switch only the first statement would execute because it was true.
But I had to change the logic to get to the result that I wanted.
iif(
Parameters!EndMonth.Value = 1,
ReportItems!txtTotal1.Value,
Parameters!EndMonth.Value = 2,
ReportItems!txtTotal2.Value,
and so on
)
This solved my problem. Thanks guys I appreciate it.

Try using separated IIF Statements:
=iif(
Parameters!StartMonth.Value <= 1 AND Parameters!EndMonth.Value >= 1,
ReportItems!txtTotal2.Value, Nothing
) OR
iif(
Parameters!StartMonth.Value <= 2 AND Parameters!EndMonth.Value >= 2,
ReportItems!txtTotal3.Value, Nothing
) OR
iif(
Parameters!StartMonth.Value <= 3 AND Parameters!EndMonth.Value >= 3,
ReportItems!txtTotal4.Value, Nothing
)

Syntax looks correct at first glance. Most places in SSRS you are required to have = to start your statement. Your code above refers to embedded code for CalculateFraction() Does that exist and is it used successfully elsewhere?

Related

Get hours from schedule

How can I get the total working hours scheduled with this format?
Expected output should be 46.
Not the prettiest things, but here are two ways to tackle it
=ARRAYFORMULA(
SUM(
IFERROR(
INDEX(SPLIT(TRANSPOSE(A2:G2)," - ",FALSE,TRUE),0,2)-
INDEX(SPLIT(TRANSPOSE(A2:G2)," - ",FALSE,TRUE),0,1)))*
24)
or
=ARRAYFORMULA(
SUM(
IFERROR(
REGEXEXTRACT(A2:G2,"- (\d+:\d+)")-
REGEXEXTRACT(A2:G2,"^(\d+:\d+)")))*
24)
Either way, we extract the second values then subtract the first values from that, sum it, and multiply it by 24.
For overnight shifts, try this
=ARRAYFORMULA(
SUM(
IFERROR(
IF(
--REGEXEXTRACT(A2:G2,"- (\d+:\d+)")<(--REGEXEXTRACT(A2:G2,"^(\d+:\d+)")),
1+REGEXEXTRACT(A2:G2,"- (\d+:\d+)")-
REGEXEXTRACT(A2:G2,"^(\d+:\d+)"),
REGEXEXTRACT(A2:G2,"- (\d+:\d+)")-
REGEXEXTRACT(A2:G2,"^(\d+:\d+)")))*
24))
in [hh]:mm:ss
=ARRAYFORMULA(
TEXT(
SUM(
IFERROR(
IF(
--REGEXEXTRACT(A2:G2,"- (\d+:\d+)")<(--REGEXEXTRACT(A2:G2,"^(\d+:\d+)")),
1+REGEXEXTRACT(A2:G2,"- (\d+:\d+)")-
REGEXEXTRACT(A2:G2,"^(\d+:\d+)"),
REGEXEXTRACT(A2:G2,"- (\d+:\d+)")-
REGEXEXTRACT(A2:G2,"^(\d+:\d+)")))),
"[hh]:mm:ss"))

Array formula not working, what do I have wrong?

Why is this formula not working? Trying to find the next date equal or greater than today in column K but using a query to filter out some items. Thanks for the help.
=ArrayFormula(QUERY(Sheet1!B6:K,"select K where B contains '303'")TO_DATE(MIN(if(Sheet1!K:K>=today(),Sheet1!K:K'!K:K))))
Try:
=MIN(
QUERY(
Sheet1!B6:K,
"SELECT K
WHERE B CONTAINS '303'
AND K >= toDate(now())"
)
)
Or:
=MIN(
FILTER(
Sheet1!K6:K,
REGEXMATCH(Sheet1!B6:B, "303"),
Sheet1!K6:K >= TODAY()
)
)

Typechecking error involving the andalso macro in ATS

Here are two pieces of code I think are equivalent aside from the second one having more lines then it should:
fun
move_ul
{i:nat}
(
p: int(i)
, ms: list0(Int)
): list0(Int) =
if p - 5 >= 0 andalso p % 4 != 0 then
move_ul(p - 5, cons0(p - 5, ms))
else
ms
fun
move_ul
{i:nat}
(
p: int(i)
, ms: list0(Int)
): list0(Int) =
if p % 4 != 0 then
if p - 5 >= 0 then
move_ul(p - 5, cons0(p - 5, ms))
else
ms
else
ms
For some reason the second one survives type checking and the first does not (failure to satisfy constraints)... can someone tell me why?
This is due to the way andalso is defined (as a macro that does not use dependent types). If you change andalso to * (which overloads the boolean multiplication), the first version of your code should typecheck.
By the way, if orelse is used, a similar situation can simply be resolved by replacing orelse with + (which overloads the boolean addition).

What is the point of having "x...n" in Ruby?

I'm just curious.
Arent both of the code snippets below doing the same thing? Why would someone want to use ... instead of .., wouldnt .. be easier to read?
for x in 1...11
puts x
end
for x in 1..10
puts x
end
Sorry if this is too subjective, I just dont understand why I would want to go from 1 to (n-1) instead of 1 to n
10.5 is included in 1...11, but not in 1..10.
It's not 1 to n vs. 1 to (n - 1), it's 1 <= x <= n vs. 1 <= x < m.
Sometimes the index in some data structure goes form 0 to struct.size() - 1. It's helpful then to have a way of saying this:
a = ['a','b','c']
for i in 0 ... a.length
puts a[i]
end
will print 'a', 'b', 'c'. It you use the .. form it will print an additional nil.
If you use n - 1, then if n is 0, you would have n - 1 of -1, which is used to indicate the end of an array.
array[0...0] # Returns no elements
array[0..-1] # Returns all elements

Add even elements in Prolog- Problem with 'amt' variable

I'm trying to figure out how to add even elements in a list (i've studied examples but cant do it on my own yet, need your help in pinning down my lack of understanding to a specific area).
The input I used is start([1,2,3,4,5]). There is no compilation error, but I dont get any output. I'm not sure what the logical error is..could you please advise?
(please see below for the latest update, after revising my code, now it works, and the problem lies in the way I use 'amt', but I dont know why!)
Original code that didnt work:
start(X):- add(X,1,amt), write(amt).
add([],_,0).
add([H|Tail],Cnt,amt):-
T is (Cnt mod 2), T == 0, Cnt1 is Cnt + 1, add(Tail,Cnt1,Y), amt is H+Y;
T is (Cnt mod 2), T =\=0, Cnt1 is Cnt + 1, add(Tail, Cnt1, amt).
Latest Update:
I replaced 'amt' with a 'S', and it works! But why wldnt it work with 'amt'?
here's the revised code that works:
start(X):- add(X,1,S), write(S).
add([],_,0).
add([H|Tail],Cnt,S):-
T is (Cnt mod 2), T == 0, Cnt1 is Cnt + 1, add(Tail,Cnt1,Y), S is H+Y;
T is (Cnt mod 2), T =\=0, Cnt1 is Cnt + 1, add(Tail, Cnt1, S).
Thanks :)
Are you intending to display amt1?

Resources