SSRS expression for date difference to a number - ssrs-2012

I have this expression:
=COUNT(Fields!RecId.Value) -
IIF(Fields!Status.Value="Assigned",
DATEDIFF("d", Fields!CreatedDateTime.Value,Fields!ResolvedDateTime.Value),
DATEDIFF("d", Fields!CreatedDateTime.Value,Fields!AssignedDateTime.Value))
- IIF(Weekday(Parameters!StartDate.Value, 1) = 1, 1, 0)
- IIF(Weekday(Parameters!StartDate.Value, 1) = 7, 1, 0)
- IIF(Weekday(Parameters!EndDate.Value, 1) = 1, 1, 0)
- IIF(Weekday(Parameters!EndDate.Value, 1) = 7, 1, 0)
What I want to be able to return is the RecID value minus the date difference if the date is more than 1 day.

From the comment, it seems like you want the count of records minus the number of records where the work days between the Created Date and if Status is "Assigned" the Resolved Date else the Assigned Date.
=COUNT(Fields!RecId.Value) -
SUM(
IIF(Fields!Status.Value = "Assigned",
IIF(DATEDIFF("d", Fields!CreatedDateTime.Value, Fields!ResolvedDateTime.Value)
- (DateDiff(DateInterval.WeekOfYear, Fields!CreatedDateTime.Value, Fields!ResolvedDateTime.Value)*2)
- (IIF(WEEKDAY(Fields!CreatedDateTime.Value) = 7, 1, 0)
- (IIF(WEEKDAY(Fields!ResolvedDateTime.Value) = 6, 1, 0))
- 1) > 1, 0, 1)
,
IIF(DATEDIFF("d", Fields!CreatedDateTime.Value, Fields!AssignedDateTime.Value) > 1, 0, 1)
- (DateDiff(DateInterval.WeekOfYear, Fields!CreatedDateTime.Value, Fields!AssignedDateTime.Value) * 2)
- (IIF(WEEKDAY(Fields!CreatedDateTime.Value) = 7, 1, 0)
- (IIF(WEEKDAY(Fields!AssignedDateTime.Value) = 6, 1, 0))
- 1) > 1, 0, 1)
)

Related

how can I sort parameters in pyomo?

I am working with the Pyomo package(for mathematical modeling in python).I have a parameter defined as: model.D=Param(model.t,model.i) .this is a multi-dimensional parameter. t is for the range of time periods, i is for the range of instances and D is the value of the demand. how can I sort this parameter by its value and get the corresponding t and i ?
Do all that data cleaning/sorting stuff with basic python before you build the model. Part of this answer depends on the original format of the data and the format you'd like your answer in, but I think the overall gist is clear....
Code
import pyomo.environ as pyo
d = { 0: [1.2, 3.1, 0.5],
1: [9.5, 2.0, 3.1] }
# a good format to pass in to a parameter, tuple-indexed dictionary
d_data = {(t, i): d[t][i] for t in d for i in range(len(d[t]))}
# now let's sort the values in d for the missing info on order
d_tuples = {t: sorted([(val, idx) for idx, val in enumerate(d[t])]) for t in d}
d_sorted = {t: [temp[1] for temp in d_tuples[t]] for t in d}
print(d_data)
print(d_tuples)
print(d_sorted)
# now set up the model...
m = pyo.ConcreteModel()
m.T = pyo.Set(initialize=d.keys())
m.I = pyo.Set(initialize=list(range(len(d[0])))) # assumes all d[t] are equal length
m.D = pyo.Param(m.T, m.I, initialize=d_data)
m.pprint()
Yields:
{(0, 0): 1.2, (0, 1): 3.1, (0, 2): 0.5, (1, 0): 9.5, (1, 1): 2.0, (1, 2): 3.1}
{0: [(0.5, 2), (1.2, 0), (3.1, 1)], 1: [(2.0, 1), (3.1, 2), (9.5, 0)]}
{0: [2, 0, 1], 1: [1, 2, 0]}
3 Set Declarations
D_index : Size=1, Index=None, Ordered=True
Key : Dimen : Domain : Size : Members
None : 2 : T*I : 6 : {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)}
I : Size=1, Index=None, Ordered=Insertion
Key : Dimen : Domain : Size : Members
None : 1 : Any : 3 : {0, 1, 2}
T : Size=1, Index=None, Ordered=Insertion
Key : Dimen : Domain : Size : Members
None : 1 : Any : 2 : {0, 1}
1 Param Declarations
D : Size=6, Index=D_index, Domain=Any, Default=None, Mutable=False
Key : Value
(0, 0) : 1.2
(0, 1) : 3.1
(0, 2) : 0.5
(1, 0) : 9.5
(1, 1) : 2.0
(1, 2) : 3.1
4 Declarations: T I D_index D

Pattern recognition in binary numbers (pseudo code or MQL5)

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
. . 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0
Recognition starts at 17 and goes backwards to 0.
What can be seen is the most simple pattern.
Pattern starts with at least three 0s or three 1s but could be more of each but not mixed!
First pattern is then followed by at least five 0s or five 1s depending on what came in the first pattern. Since pattern one contains three 0, there must be at least five 1s and vice versa
Then we want to see the first pattern again. At least three 0s or three 1s, again, depending wheather there were 1s or 0s before
Finally we want to see the second pattern again, which means at least five 0s or five 1s, again, depending on which pattern was seen before
I tried using for loops and counters but did not manage to work it out. What is struggling me is the fact, that the pattern is not of fixed size as there can be more than three or five 0s and 1s in succession.
Is anybody able to provide some pseudo code how to implement this or even some MQL5 code?
The following Swift code is everything else than optimal. It should just give you hints how you could implement it.
A function to match a single pattern:
func matchPattern(numbers: [Int], startIndex: Int, number: Int) -> Int {
var actualIndex = startIndex
while numbers[actualIndex] == number && actualIndex > 0 {
actualIndex = actualIndex - 1
}
return startIndex - actualIndex
}
A function to match the 4 patterns:
func match(binNrs: [Int]) -> Bool {
let firstPatternNr = binNrs[17]
let secondPatternNr = firstPatternNr == 0 ? 1 : 0
let pattern1Length = matchPattern(numbers: binNrs,
startIndex: 17,
number: firstPatternNr)
if pattern1Length < 3 { return false }
let pattern2Length = matchPattern(numbers: binNrs,
startIndex: 17 - pattern1Length,
number: secondPatternNr)
if pattern2Length < 5 { return false }
let pattern3Length = matchPattern(numbers: binNrs,
startIndex: 17 - pattern1Length - pattern2Length,
number: firstPatternNr)
if pattern3Length < 3 { return false }
let pattern4Length = matchPattern(numbers: binNrs,
startIndex: 17 - pattern1Length - pattern2Length - pattern3Length,
number: secondPatternNr)
return pattern4Length >= 5
}
Some test patterns with results:
let match1 = match(binNrs: [0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0]) // true
let match2 = match(binNrs: [1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) // false (4th sequence < 5)
let match3 = match(binNrs: [0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0]) // false (1st sequence < 3)
let match4 = match(binNrs: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1]) // false (2nd sequence < 5)

how to group by columnA and sum columnB, columnC in mixpanel JQL

I have a JQL in mixpanel. I managed to get to a result in the following format:
key, count1, count2, count3
a , 10, 0, 0
a , 0, 3, 0
a , 0, 0, 7
b , 2, 0, 0
b , 0, 3, 0
b , 0, 0, 5
And I'd like to get the results like:
key, count1, count2, count3
a , 10, 3, 7
b , 2, 3, 5
In other words: groupBy(['key'], WHAT_REDUCER_DO_I_NEED???)
You can use multiple reducers in your groupBy statement like this
.groupBy(['key'], [
mixpanel.reducer.sum('count1'),
mixpanel.reducer.sum('count2'),
mixpanel.reducer.sum('count3')
])
.groupBy(["key"], function(accumulators, events){
var sum = {"count1":0,"count2":0,"count3":0};
for (var i = 0; i < accumulators.length; ++i) {
sum["count1"] += accumulators[i]["count1"];
sum["count2"] += accumulators[i]["count2"];
sum["count3"] += accumulators[i]["count3"];
}
for (i = 0; i < events.length; ++i) {
var event = events[i];
sum["count1"] += event["count1"];
sum["count2"] += event["count2"];
sum["count3"] += event["count3"];
}
return sum;
})

SSRS Divide by zero error

I am getting NaN in 3 places in my SSRS report. I believe it is because I am dividing by 0. I am trying to find the average days for prescriptions on-time, late, and not filled. The 3 expressions that I was given are below. What and where would I need to insert the iif statement addressing the 0 issue. I am new to this
=sum(iif(Fields!DaysDifference.Value >= -1 and Fields!DaysDifference.Value <= 1 and Fields!ActualNextFillDateKey.Value <> 0, Fields!DaysDifference.Value,0))/
sum(iif(Fields!DaysDifference.Value >= -1 and Fields!DaysDifference.Value <= 1 and Fields!ActualNextFillDateKey.Value <> 0, 1,0))
=sum(iif(Fields!DaysDifference.Value > 1 and Fields!ActualNextFillDateKey.Value <> 0, Fields!DaysDifference.Value,0))/
sum(iif(Fields!DaysDifference.Value > 1 and Fields!ActualNextFillDateKey.Value <> 0, 1,0))
=sum(iif(Fields!ActualNextFillDateKey.Value = 0, Fields!DaysDifference.Value, 0))/
sum(iif(Fields!ActualNextFillDateKey.Value = 0, 1, 0))
Instead of using 0, you should be dividing by your field:
=SUM(IIF(Fields!ActualNextFillDateKey.Value = 0, Fields!DaysDifference.Value, 0))/
SUM(IIF(Fields!ActualNextFillDateKey.Value = 0, 1, Fields!ActualNextFillDateKey.Value))

Hand tracing a pseudo code

I have this pseudo code that I need to hand trace:
begin
count <- 1
while count < 11
t <- (count ^ 2) - 1
output t
count <- count + 1
endwhile
end
I am unsure what <- means and I don't really understand what to do with the t. I also keep getting 1,1,1, etc. every time I go through. Any help would be appreciated!
First off the operator <- means "gets", as in an assignment. So:
count <- count + 1
Means to set the variable count to the value count + 1.
Second the program will output the first 10 values of x2-1, so:
t <- count^2 - 1
will evaluate to:
0, 3, 8, 15, 24, 35, 48, 63, 80, 99
for the values of count
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
respectively.
here is the code for it in C++, hope it helps:
int count = 1; // count <- 1
int t;
while ( count < 11 ){ // while count < 11
t = count * count - 1; // t <- (count ^ 2) - 1
std::cout<<t<<std::endl; // output t
count ++; // count <- count + 1
} // endwhile
and as said in the previous answer:
count takes the values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
and t will take the values: 0, 3, 8, 15, 24, 35, 48, 63, 80, 99

Resources