Finding a value in a multi select list parameter in report? - jasper-reports

I have a multi select input parameter for a report.
We know how to find whether a values is present in that parameter or not by using
$X{IN, colName, paramName}
the above expression in WHERE condition clause.
That is working fine.
But how will we find whether a variable ( let say having value 3 ) is present in parameter ( same multi select list let say [ 1, 2 ,3, 5] ) or not.
By validating the above condition i want to display something in report's static text field.

Related

Need help in re-order / sort Bars in Bar Chart in Qliksense

I am trying to reorder the Bars in bar chart in qliksense. Below is the order which I have to sort the bars.
NEW
IN_PROGRESS_PL
ASSIGNED
IN_PROGRESS_SPOC
RESOLVED/CLOSED
FBS E2S BACKLOG
CANCELLED
DUPLICATE
But by default the bars are ordered in alphabetical order or by the numbers, I have tried the below solution, but it still didn't rearranged the bars.
Default order :
Match('NEW','IN_PROGRESS_PL','ASSIGNED','IN_PROGRESS_SPOC','RESOLVED/CLOSED','FBS E2S BACKLOG' , 'CANCELLED','DUPLICATE' )
Can someone please help me to fix this issue.
The first parameter in Match is the targeted field.
If we have data like:
RawData:
Load * inline [
Stage , IdeasCount
ASSIGNED , 63
CANCELLED , 11
INTERNAL_123, 2
IN_PROGRESS1, 20
IN_PROGRESS2, 47
];
Then the sorting expression will be:
=match(Stage, 'IN_PROGRESS1', 'ASSIGNED', 'IN_PROGRESS2', 'INTERNAL_123', 'CANCELLED')
The sorting properties:
And the result chart will have the correct sorting:
P.S. (1)
Have to mention that if the value is not found in the Match function then the function will return null and thus the corresponding bar will be pushed in the front. In this case you can wrap the match in if statement and if no matching value is found then assign some large number:
= if( match(Field, 'value1', 'value2' ...) > 0,
match(Field, 'value1', 'value2' ...),
1000
)
P.S. (2)
In your case you can also use Dual function to create "default" sort order for a specific field.
If we change the script to:
RawData:
Load
Dual(Stage, OrderId) as Stage,
IdeasCount
;
Load * inline [
Stage , IdeasCount, OrderId
ASSIGNED , 63 , 2
CANCELLED , 11 , 5
INTERNAL_123, 2 , 4
IN_PROGRESS1, 20 , 1
IN_PROGRESS2, 47 , 3
]
;
The result table will look the same - with two fields only Stage and IdeasCount. But in the background each value of Stage field will have and number representation (based on the initial OrderId field). And as a side effect of that the auto sorting option will sort the field data by its internal number representation and the chart will "sort itself" correctly

How to update multiple rows by keeping some column values the same and updating others?

I am trying to bulk update some rows in postgres. Now not all of the rows need to update the same column values. For example, row 1 needs to update column 1 and 3 whereas row 2 needs to update column 2 and 4. so row 1 column 2 and 4 should not change and row 2 column 1 and 3 should not change.
I have tried using CASEs to conditionally SET the correct column values but it doesn't work with multiple rows. It DOES work if I only try to update 1 row at a time.
update topic as tmp set
"from" = (CASE WHEN tmp2."from2"::text = 'OLD_VALUE' THEN tmp."from"::int2 ELSE tmp2."from2"::int2 end),
"text_search" = (CASE WHEN tmp2."text_search2"::text = 'OLD_VALUE' THEN tmp."text_search"::text ELSE tmp2."text_search2"::text end),
"weight" = (CASE WHEN tmp2."weight2"::text = 'OLD_VALUE' THEN tmp."weight"::numeric ELSE tmp2."weight2"::numeric end)
from (values
(1051,1,'Electronic Devices',3),
(1052,'OLD_VALUE','OLD_VALUE',100)
) as tmp2("id2","from2","text_search2","weight2")
where tmp2."id2" = tmp."id"
This is the error message i get
SQL Error [22P02]: ERROR: invalid input syntax for type integer: "OLD_VALUE"
When I try with only 1 FROM value
from (values (1051,1,'Electronic Devices',3))
or
from (values (1052,'OLD_VALUE','OLD_VALUE',100))
it works correctly.
It even works correctly if the same columns need to be updated eg.
from (values
(1051,1,'Electronic Devices',3),
(1052,2,'Topic 2',100)
)
Why is it not working correctly when I need to update different columns for each row?
When you provide the list of values as values (1051,1,'Electronic Devices',3),(1052,'OLD_VALUE','OLD_VALUE',100)), the first set of values is interpreted as the "template" of data types, and in this case (1051,1,'Electronic Devices',3), it's int, int, text, int. Then, any subsequent values provided, will be expected to have the same data type signature. When it parses (1052,'OLD_VALUE','OLD_VALUE',100), it sees int,text,text,int, which doesn't match the data type signature it expects, so it reports an error.
When you omit the first value and provide only (1052,'OLD_VALUE','OLD_VALUE',100), then it identifies int,text,text,int as the "template" data type signature, and it proceeds without complaint.

I am trying to create a formula with multiple parameters that may or may not have a value entered

I am trying to create a formula with multiple parameters that may or may not have a value entered.
The database field and corresponding parameters are:
{DataTableTicket.Master_Account_Code}={?MastNo})
{DataTableTicket.Description}={?RTCode}
{DataTableTicket.Problem_Code}={?ProbCode}
{DataTableTicket.Resolution_Code}={?ResCode}
{DataTableTicket.Customer_Number}={?CustNo}
{DataTableTicket.Master_Account_Code}={?MastNo})
I am trying to write an IF THEN statement that takes into consideration the various combinations, since you can enter in a ?MastNo value but not populate the rest of the parameters.
I think the basic formula would be something like this (if parameter is blank then all records else parameter). What I am struggling with is how to get that basic formula created since there are so many combinations.
For each parameter that "may or may not have a value", set it to a default value.
If the value for the parameter is entered then set the parameter to the entered value.
I usually do something like:
// Assumes that 0 represents all values; single value; numeric
( 0={?Parameter} OR {Table.Field}={?Parameter} )
// Assumes that 0 represents all values; multiple values; numeric
( 0 IN {?Parameter} OR {Table.Field} IN {?Parameter} )
In your situation:
( 0={?MastNo} OR DataTableTicket.Master_Account_Code}={?MastNo} ) AND
( 0={?RTCode} OR {DataTableTicket.Description}={?RTCode} )
...

MDX query not accepting date values

I'm a SSAS newbie and i'm trying to query a cube to retrieve data against aome measure groups order by date. The date range i wish to specify in my query. The query I'm using is this:-
SELECT
{
[Measures].[Measure1],
[Measures].[Measure2],
[Measures].[Measure3]
}
ON COLUMNS,
NON EMPTY{
[Date].[AllMembers]
}
ON ROWS
FROM (SELECT ( STRTOMEMBER('2/23/2013', CONSTRAINED) :
STRTOMEMBER('3/1/2013', CONSTRAINED) ) ON COLUMNS
FROM [MyCube])
However it gives me the following error
Query (10, 16) The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function were violated.
I tried removing the constrained keyword and then even strtomember function. But in each cases i got the following errors respectively
Query (10, 16) The STRTOMEMBER function expects a member expression for the 1 argument. A string or numeric expression was used.
and
*Query (10, 14) The : function expects a member expression for the 1 argument. A string or numeric expression was used.
*
I can understand from the last two errors that i need to include the constraint keyword. But can anyone tell me why this query wont execute?
The string that you pass as the member expression must be a fully-qualified member name, or resolve to one. Use the same format as you did in the SELECT.
For example:
STRTOMEMBER('[Date].[2/23/2013]', CONSTRAINED)
Edit: I just noticed the syntax of your range select looks wrong -- you need to use {...}, not (...).
SELECT {
STRTOMEMBER('2/23/2013', CONSTRAINED) :
STRTOMEMBER('3/1/2013', CONSTRAINED) }
Please execute below script.
Extract your date dimension attribute copy it by right clicking and paste it in STRTOMEMBER value.
It will works fine.
SELECT NON EMPTY { [Measures].[Internet Sales Amount] } ON COLUMNS
FROM ( SELECT ( STRTOMEMBER('[Date].[Date].&[20050701]') :
STRTOMEMBER('[Date].[Date].&[20061007]') ) ON COLUMNS
FROM [Adventure Works])
FROM ( SELECT (
STRTOMEMBER(#FromDateCalendarDate, CONSTRAINED) :
STRTOMEMBER(#ToDateCalendarDate, CONSTRAINED) ) ON COLUMNS

SSRS - Refine WHERE Criteria in T-SQL Query

I am developing a report that should return results depending on user-specified parameters. There are 3 report parameters, one is a drop down with 'Locations', and the other two are text parameters to search within 'user_id' and users' first or last name. This is what I am currently using:
SELECT *
FROM UserTable1
WHERE Location = #Location
AND (user_id LIKE '%'+#SearchUserID+'%'
AND first_name LIKE '%'+#SearchUserName+'%'
OR last_name LIKE '%'+#SearchUserName+'%')
If the #SearchUserID parameter field is left blank by the user, all user_ids should be returned (that meet the other 2 parameters). If specified, it will return user_ids that have that substring in the user_id. Same thing goes for the #SearchUserName parameter field. If left blank, it should return all users that meet the other parameters. If specified, it should return all users that have that substring in their first_name or last_name (but only results that meet the other parameters). If both are left blank, it should return all users.
The query I have above is not working. It seems to just return results meeting the #SearchUserName parameter, but disregards the #SearchUserID parameter. Is there a way to fix this? I had put the #SearchUserID filter on the tablix itself, using the expression:
="" & Parameters!SearchUserID.Value & ""
But this has resulted in severely hampered performance..
Try this. You must pass NULL if parameter is blank(empty).
SELECT *
FROM UserTable1
WHERE Location = #Location
AND (user_id LIKE '%'+#SearchUserID+'%'
OR #SearchUserID IS NULL
)
AND (first_name LIKE '%'+#SearchUserName+'%'
OR last_name LIKE '%'+#SearchUserName+'%'
OR #SearchUserName IS NULL
)
"....but disregards the #SearchUserID parameter." What data type of user_id?