OBIEE case statement check on non excistence - obiee

I have the following situation:
column 1 column 2 column 3
A 1 1
A 1 2
B 3 4
B 3 5
I need to color my letters when the value in column 2 never occurs in column 3. But I need to color all my letters. Does anyone know how to write a case statement for this?
So I'll explain my example: I dont't need to color the letter A because there is a match between column 2 and 3 and the first row.
I do need to color my B's because there is never a match between columns 2 and 3.
I already tried this:
count(distinct(case when "Column 2" != "Column 3" then 1 else 0 end))
but this gives a result for each row and I need a result for the total package.
Thanks!

You can approach this as following:
Create a logical column on your analysis that does a case statement that returns 1 or 0 depending if the values of column2 and column3 are the same (pretty much like the case-when that you provided on your answer but without the count distinct).
Wrap that case statement with a MAX grouped by your column1. This will give you either a consistent 1 or 0 across all your different values of column1. You can use this value for your conditional formatting. The key here is to use the aggregated function with the group by.
You have here some oracle documentation on how to use the logical SQL group by.
Hope that helps! Good luck!

Related

how to sort 2 different columns in google sheet individually?

I have a Google Sheet that has 2 columns with integer rows in it. Both these columns have no relation to each other. But when I apply a A->Z sort on the 1st column the 2nd column values also change and vice versa. My task is to SORT these 2 columns individually in ascending order and create a 3rd column which checks if the values of this 1st 2 column are equal or not.
Example:
Col1 Col2
4 5
1 8
2 9
5 1
Expected Output after sorting them individually:
col1 col2
1 1
2 5
4 8
5 9
Solution 1:
You can filter and sort each column separately:
Solution 2:
Another solution would be to create the desired output by sorting each column separately and concatenating the results:
={{"Col1";sort(A2:A)},{"Col2";sort(B2:B)}}

Complex count row etl requirement

I have a requirement related as below
1-If there is employee record then count the number of rows
a-if there are four rows then follow the layout 1,
and populate the column1 and column 2 with values in report and ltrimrtrim
b- if there are three rows, then follow the layout 2,
and hardcode the column 1 and column 2 with NULL
Otherwise, look for the employee record.
Couldn't get the logic, I used the router with as if column 1 and two null the send to layout two else 1. But the requirement is different.
router transformation, if null, layout one else 2
Step 1 - Use SRT>AGG>JNR to calculate count. create new column as count_all and set to COUNT(*). Please group by proper key columns.
Step 2 - Use RTR next to split data based on your condition.
group 1- count_all =4 then follow the layout 1 and...
group 2- count_all =3 then follow the layout 2 and...
group 3 - if count <3 then do employee record.

SSRS Switch Case - how to sort by 2 field values

=Switch(Fields!RptSeq.Value="1",Fields!PatientId.Value,
Fields!RptSeq.Value="2",Fields!RxNumber.Value,Fields!PatientId.Value
Fields!RptSeq.Value="5",Fields!DoctorName.Value,Fields!PatientId.Value,
1=1,Fields!PatientId.Value)
I need to sort my report thrugh expression like this, if the sort seq is 1 then by patient ID, if 2 then the report should be first sorted by RxNumber then by PatientID. I don't know how to sort for 2 field values.
if I do Fields!RxNumber.Value,Fields!PatientId.Value the sort does not work, if I do Fields!RxNumber.Value+Fields!PatientId.Value I'm getting error wrong sort expression.
appreciate your help
Thanks in advance.
you can add two lines in the sorting tab of the tablix; one for the first sort priority with this expression:
=Switch(Fields!RptSeq.Value="1",Fields!PatientId.Value,
Fields!RptSeq.Value="2",Fields!RxNumber.Value,
Fields!RptSeq.Value="5",Fields!DoctorName.Value,
1=1,Fields!PatientId.Value)
and the other for the second sort priority set the field to :
Fields!PatientId.Value
You can handle it by passing the parameter to the Dataset query also.
Sample:
declare #RptSeq int = 1
select * from Table
order by
(case #RptSeq when 1 then PatientId
when 2 then RxNumber
when 5 then DoctorName
else PatientId
end),
(case #RptSeq when 2 then PatientId
when 5 then PatientId
end)

Stacked column Flash chart counting all values

I am building stacked column flash chart on my query. I would like to split values in column for different locations. For argument sake I have 5 ids in location 41, 3 ids in location 21, 8 ids in location 1
select
'' link,
To_Char(ENQUIRED_DATE,'MON-YY') label,
count(decode(location_id,41,id,0)) "location1",
count(decode(location_id,21,id,0)) "location2",
count(decode(location_id,1,id,0)) "location3"
from "my_table"
where
some_conditions = 'Y';
as a result of this query Apex is creating stacked column with three separate parts( hurray!), however it instead of having values 5,3 and 8, it returns three regions 16,16,16. ( 16 = 5 +3+8).
So obviously Apex is going through all decode conditions and adding all values.
I am trying to achieve something described in this
article
Apex doesn't appear to be doing anything funky, you'd get the same result running that query through SQL*Plus. When you do:
count(decode(location_id,41,id,0)) "location1",
.. then the count gets incremented for every row - it doesn't matter which column you include, and the zero is just treated as any fixed value. I think you meant to use sum:
sum(decode(location_id,41,1,0)) "location1",
Here each row is assigned either zero or one, and summing those gives you the number that got one, which is the number that had the specified id value.
Personally I'd generally use caseover decode, but the result is the same:
sum(case when location_id = 41 then 1 else 0 end) "location1",

Convert Character to Number in Oracle

I have ColumnA in table. The data of each row is single character between A & H.
I want my select query to return 1 for 'A', 2 for B .... 8 for H.
My query always returns only one row. I can make a lookup table.
Anyone has better ideas to achieve the same ?
SELECT 1 + ASCII(columnA) - ASCII('A')
FROM table

Resources