Oracle Goldengate - IF statement - Not equal - oracle-golden-gate

#STREQ(INITIAL, 'F') will return TRUE if INITIAL column has value F
I want to check cases where INITIAL <> F

You can use the #IF function. For example:
#IF(#STREQ(INITIAL, 'F'), 0, 1)
From the documentation:
The following compares the value of the region column to the literal value EAST. If region = EAST, the record passes the filter.
FILTER (#STREQ (region, 'EAST'))
You could use #STREQ in a comparison to determine a result, as shown in the following example. If the state is NY, the expression returns East Coast. Otherwise, it returns Other.
#IF (#STREQ (state, 'NY'), 'East Coast', 'Other')

Related

Counting true/false values form measure 'A', in measure 'B' on matrix visual

I have a riport, in which I need to make a measure, which counts the 'true' values of another measure.
My partner's sales prices are calculated with a measure, which is then put into a matrix visual.
Column 'A' contains the partner name (as there are several) Column 'B' is the item name, 'C' is their sales price and 'D' is the price they should sell the product for.
Example_1 matrix visual with open hierarchy:
What I need, is a measure, that I can put into the matrix, which then calculates those items, that are not sold for the given price, so when I close the table hieararchy and I only see the partner's name, I should have the info of how many products they sell for lower than given sales price (making it easier to rank them)
What I'm having trouble with, is to count the 'true' values of a measure, with another measure.
It's important, that I cannot make a new colmn into the source tables. I must have a measure, which counts 'True' values of another, as their sales prices are also calculated.
Example_2 matrix visual with closed hieararchy with the needed result value:
The first two items from Example_1 were sold for a lower than given price. My first measure will determine this by doing a true/false logical test.
My second measure which gives back two, should calculate the 'true' values of the first measure.
Practically the measures should look like this:
Measure_1 = if([measure_salesprice] < sum('given_pricelist'[Price] , "Lower" , "Not lower")
--> this one works perfectly
Measure_2 = Calculate(DISTINCTCOUNTX('Sales table', 'Sales table[Item name]),[measure_lowerpricetruorfalse] = "Lower")
--> now, this doesn't
Is this possible somehow?
I've tried several DAX combinatains like:
Calculate --> DISTINCTCOUNT, COUNTROWS, COUNTA, COUNTAX, COUNTX( with filter)
Always the same true/false error.
Please be informed that There is no function in DAX called DISTINCTCOUNTX ----> It is DISTINCTCOUNT only as of 2 Nov 2022:
Regarding your question: Use this DAX Code As Measure:
You don't need to categorize them as Lower or not Lower if you don't need this info to use later.
YourMeasure =
VAR GroupLower = FILTER(
'Sales table', [Partner sales price] < [Given sales price])
RETURN
COUNTX(
GroupLower,[Item name])
If you try to test it on a matrix visual:

Find position of closest value to another value given a condition in R

let's say I have a vector that increases and then decreases like the simple example below. I want to identify the position (index) in the vector that is closest to a value - but with the condition that the following value must be lower (I always want to pick up the closest value on the downslope of the data).
In the example below, I want the answer to be 13 (rather than 6).
I can't think of a solution using which.min() or match.closest() which would reliably work for this.
Any help gratefully received!
# example vector which increases then decreases
vector <- c(1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1)
# index
index <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)
value <- 6.2
Maybe you can use cummax + rev like below
which.min(abs(rev(cummax(rev(vector)))-value))
which gives
[1] 13
Assuming your points always continue to decrease in value after the first decrease, and value is between the point of the first decrease and the last point, you could do this:
closest <- function(value, vec, next_is){
lead_fun <- function(x) c(tail(x, -1), NA)
meets_cond <- get(next_is)(lead_fun(vec), vec)
which.min(abs(vec[meets_cond] - value)) + which.max(meets_cond) - 1
}
closest(6.2, vec = vector, next_is = '<')
# [1] 13
Check which elements in the vector meet your condition, find the index of the closest element in that vector, then add back the number of elements before the first which meets your condition.
Edit: ----------------------------------------
Another version of the function which accepts an arbitrary logical vector which is TRUE for indices meeting a condition:
closest <- function(value, vec, cond_vec){
which.min(abs(vec[cond_vec] - value)) + which.max(cond_vec) - 1
}
Note that this assumes the values matching your condition are all in one contiguous region (not e.g. the first matches, then the third, then the sixth, etc.)
If your condition is that the point comes after the max value:
closest(6.2, vec = vector, cond_vec = seq_along(vector) > which.max(vector))
# [1] 13

How to check equality of two FStar.Set's

How can you check whether two sets are equal in FStar? The following expression is of type Type0 not Tot Prims.bool so I'm not sure how to use it to determine if the sets are equal (for example in a conditional). Is there a different function that should be used instead of Set.equal?
Set.equal (Set.as_set [1; 2; 3]) Set.empty
The sets defined in FStar.Set are using functions as representation.
Therefore, a set s of integers for instance, is nothing else than a function mapping integers to booleans.
For instance, the set {1, 2} is represented as the following function:
// {1, 2}
fun x -> if x = 1 then true
else (
if x = 2 then true
else false
)
You can add/remove value (that is, crafting a new lambda), or asks for a value being a member (that is, applying the function).
However, when it comes to comparing two sets of type T, you're out of luck : for s1 and s2 two sets, s1 = s2 means that for any value x : T, s1 x = s2 x. When the set of T's inhabitants is inifinite, this is not computable.
Solution The function representation is not suitable for you. You should have a representation whose comparaison is computable. FStar.OrdSet.fst defines sets as lists: you should use that one instead.
Note that this OrdSet module requires a total order on the values held in the set. (If you want have set of non-ordered values, I implemented that a while ago, but it's a bit hacky...)

Is it possible to create a countif like function in R using ranges?

I've already read this question with an approach to counting entries in R:
how to realize countifs function (excel) in R
I'm looking for a similar approach, except that I want to count data that is within a given range.
For example, let's say I have this dataset:
data <- data.frame( values = c(1,1.2,1.5,1.7,1.7,2))
Following the approach on the linked question, we would develop something like this:
count <- data$values == 1.5
sum(count)
Problem is, I want to be able to include in the count anything that varies 0.2 from 1.5 - that is, all possible number from 1.3 to 1.7.
Is there a way to do so?
sum(data$values>=1.3 & data$values<=1.7)
As the explanation in the question you linked to points out, when you just write out a boolean condition, it generates a vector of TRUEs and FALSEs the same length as your original dataframe. TRUE equals 1 and FALSE equals 0, so summing across it gives you a count. So it simply becomes a matter of putting your condition as a boolean phrase. In the case of more than one condition, you connect them with & or | (or) -- much the same way that you could do in excel (only in excel you have to do AND() or OR()).
(For a more general solution, you can use dplyr::between - it's also supposed to be faster since it's implemented in C++. In this case, it would be sum(between(data$values,1.3,1.7).)
Like #doviod writes, you can use a compound logical condition.
My approach is different, I wrote a function that takes the vector and as range the center point value and the distance delta.
After a suggestion by #doviod, I have set a default value delta = 0, so that if only value is passed, the function returns
a count of cases where the values equal the value the user provides.
(doviod, in the comment)
countif <- function(x, value, delta = 0)
sum(value - delta <= x & x <= value + delta)
data <- data.frame( values = c(1,1.2,1.5,1.7,1.7,2))
countif(data$values, 1.5, 0.2)
#[1] 3
which identifies the location of all values in your vector that satisfy your criterion, and length subsequently counts the 'hits'.
length( which(data$values>=1.3 & data$values<=1.7) )
[1] 3

return value of the dataset where the other variable meets condition in R

I have a dataframe "my_data" and I am trying to return the name of the restaurant that has the highest rating.
What is the function I can apply? I tried this:"my_data$Name(which(max(my_data$rating)))"
It did not work.
Thank you
> Name city rating
1 a new york 4.5
2 b new jersey 3.0
3 c rohde island 5.0
4 d xyz 2.0
We can use which.max to get the position index of the max value and then the corresponding 'Name' can be extracted based on that.
my_data$Name[which.max(my_data$rating)]
#[1] "c"
In the OP's code, there are a couple of mistakes.
which(max( - The max returns the maximum value. which would be used to return the numeric position based on a logical index. i.e. which(mydata$rating == max(mydata$rating) will return the position.
my_data$Name( - If the first case was correct, then we only need to subset it. For that, we use square ([) brackets. Usually, the ( is used for function calls i.e. mean(x), max(x) etc..

Resources