Two Date Fields, One Date Filter - cognos

Depending on a condition, [Example] = 'Business', I want to filter by [Date A] or [Date B]
I have written out a statement like such from the query page in the filter section but am getting a error. I plan to ad x_date as the parameter to a prompt page but can't seem to get this to work. I guess I can create two separate reports and UNION them but i'm sure there is a way to knock this out with a conditional formula.
if ( [Example] = 'Business') then
[Date A] in_range ?x_date?
else
[Date B] in_range ?x_date?
Any idea how I can apply a single date filter to conditionally apply to to the target date columns?

Suggestion
Create a data item called [target date] in your query
With the expression
IF([Example] = 'Business')Then([Date A])Else([Date B])
Then add the filter for your query
[target date] = ?PromptDate?

You can try the following expression:
if ([Example]='Business')
then([Date A])
else( [Date B])
in_range ?p_date?
That being said, I think the union approach maybe more controllable given [Example] may return different values. For the Union approach you would have two queries
Query1 would have the filters Example= Business and Date A in_range ?p_date?
Query2 would have the filters Example <>Business and Date B in_range ?p_date?

Related

Microsoft Excel - Comparing 2 Column and Delete Duplicate by Row

I am facing an issue where I need to compare column X and column Y, if X=Y then I want to delete that row. But if X≠Y then just leave it there as I need to correct it manually. I try to find any reference but to no avail.
Example of Table
I try using PowerQuery, because the name list were scattered, after sorting up to X=Y, there are some data that wasnt right because it is comparing to almost identical name. I try to use 'remove duplicate' but nothing happened as it only remove if the column has the same data in multiple row.
Thanks in advance.
For another method that does not involve a helper column, you can use the Table.SelectRows function of Power Query:
let
//sample data
Source = Table.FromRecords(
{[x="Johnny White", y="Johnny White"],
[x= "Black Mmamba", y= "Black Mamba"],
[x="Tom Evans", y="Tom Evans"],
[x="Britney Blue",y="Britney Blue"],
[x="White Kingdom", y="Wine Kingdom"],
[x="Daniel Zack", y="Daniel Zack"]},
type table[x=Text.Type,y=Text.Type]),
//select rows where data not the same in each column
remDupes = Table.SelectRows(Source, each [x] <> [y])
in
remDupes
Source
Dupes Removed

presto: convert array to rows?

i have a table with array columns all_available_tags and used_tags.
example row1:
all_available_tags:A,B,C,D
used_tags:A,B
example row2:
all_available_tags:B,C,D,E,F
used_tags:F
I want to get distinct set of all_available_tags from all rows and do except the set with all used_tags from all rows. from example above, all_available_tags of all rows would be A,B,C,D,E,F and all used_tags would be A,B,F. the end result i am looking for is C,D,E
I think i need to somehow pivot the table but there could be 100s of different tags, so it is not practical to list out everyone of them. is there a good way to do this?
You can try:
with tags(at, ut) as
(
select "A,B,C,D", "A,B"
union all
select "B,C,D,E,F", "F"
)
select splitat
from tags
cross join unnest(split(at, ",")) as t1 splitat
except
select splitut
from tags
cross join unnest(split(ut, ",")) as t2 splitut

setting date range filter in saved search formula

I’m looking for some guidance on how to write date range filter within saved search formula. For example, below is what I have so far to see sales of certain type, but also need to add date filter so get only sales for this year to date. I understand I can set date filter in filter section, but I also need to add other columns in this report which will display transaction amounts of different types and dates. Thanks in advance for any input.
Formula:
CASE WHEN {transaction.type} = 'Invoice' AND {transaction.custbody1} = 'Direct' THEN {transaction.amount} end
You can use the SQL TO_CHAR function to return text portions of a date, for comparison with the corresponding text portions of sysdate. In the example you give, that would look like:
CASE WHEN {transaction.type} = 'Invoice'
AND {transaction.custbody1} = 'Direct'
AND TO_CHAR({trandate}, 'YYYY') = TO_CHAR(sysdate, 'YYYY')
THEN {transaction.amount}
END
You can use the same approach with different formats to get almost any date. You could also use EXTRACT to get slightly better performance in some situations. EXTRACT returns a number rather than text.
CASE WHEN {transaction.type} = 'Invoice'
AND {transaction.custbody1} = 'Direct'
AND EXTRACT(YEAR from {trandate}) = EXTRACT(YEAR FROM sysdate)
THEN {transaction.amount}
END
You may find TO_CHAR to be easier to use when you want to combine different parts of a date. E.G.: TO_CHAR({trandate}, 'YYYY-MM') = TO_CHAR(sysdate, 'YYYY-MM') rather than EXTRACT(YEAR from {trandate}) = EXTRACT(YEAR from sysdate) AND EXTRACT(MONTH from {trandate}) = EXTRACT(MONTH from sysdate)

Google Spreadsheet multiple column filter condition grouping syntax

This question is somewhat similar to
Google Spreadsheet multiple column filter using OR
but where as he asks for the equivalent of:
select count(*)
from Table
where A is not null and (B is not null or C is not null)
I would like to do:
select count(*)
from Table
where A is not null OR (B is not null AND C is not null)
In fact what I am trying to do is filter on a date and I have been using
=FILTER(YEAR(Hours!A2:A)=2012,MONTH(Hours!A2:A)>=8)
to give me August going forward.
but now I need to add a limit to a certain day for the month. I would need something like this:
=FILTER(MONTH(Hours!A2:A)=8, ( MONTH(Hours!A2:A)=9 AND DAY(Hours!A2:A)<=13) )
in order to have all of August and then September only up to the 13th.
Is there a Syntax that allows this?
to have all of August and then September only up to the 13th.
One way (and this would be a "general" solution for filtering between two dates):
=COUNT(FILTER(Hours!A2:A;Hours!A2:A>=DATE(2012;8;1);Hours!A2:A<=DATE(2012;9;13)))

Doctrine2 subquery

I'm trying to write a subquery in doctrine2, to sort a table ordered by date column of another table.
(let's say I'm querying table A, which has an id column, and B has an a_id and a date, in the subquery b.a_id = a.id)
I'm using query builder, and the addSelect method, but since I can't use LIMIT in my query I get this error:
SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more
than 1 row
This error is true, but how could I limit this query to 1 row, if LIMIT is not allowed in doctrine2 and when I try to do it by querybuilder (I mean the subquery) and I'm using setMaxResults, and then getDQl it is still not working.
->addSelect('(SELECT b.date FROM B b WHERE b.conversation = a.id ORDER BY b.date DESC)')
Is there any solution for my problem?
Thanks
Make the query return exactly one row. Try SELECT MAX(b.date) FROM B b WHERE b.conversation = a.id)

Resources