SSRS Display Multi Select Parameters are part of report Output - if-statement

I have a dropdown parameter that comes from a separate SQL procedure. It returns 3 strings like this ABC, XYZ, JKL. The parameter is mandatory, but the user can select 1 or 2 or all three of the values.
I need the report to display what the user selects.
For example if they select ABC and JKL I need the report to display "Shows Report: ABC, JKL.
I have the following code
="Shows Report. Hall: " & iif(isnothing(Parameters!hall.Value(0) = true),"", Parameters!hall.Value(0) & ", ") & iif(isnothing(Parameters!hall.Value(1) = true),"", Parameters!hall.Value(1) & ", ") & iif(isnothing(Parameters!hall.Value(2) = true),"", Parameters!hall.Value(2) ) & "."
However when the report runs I get an #error every time it runs.
The report does work if my code looks like this
="Shows Report. Hall: " & Parameters!hall.Value(0) & Parameters!hall.Value(1) & Parameters!hall.Value(2)
But this only works if I select all three parameters, not 1 or 2 of them. This also doesn't give me any formatting. I could add "," in between but I only want them to display if there are more then one value.
Please advise on any suggestions to fix this issue

Since it is a multi select parameter, why not just use this
="Shows Report. Hall: " + join(Parameters!hall.Value,", ")

Related

Power Query Parametrization - Choose between loading a limited number of rows or a complete rowset using a parameter

I would like my SQL query in PBI to be defined by parameter. The Parameter1 is a list of two values Big and Small. If I set up Parameter1 to Small then I want only a sample of data to be loaded. I am doing it this way:
let
ReturnQueryVar = (optional x) =>
if Parameter1 = "Small"
then " and Product in (1, 2, 3)"
else "",
Source = Sql.Database(
"myservername",
"mydatabase",
[
Query = "
select *
from table
where
1=1"
& ReturnQuery()
]
)
in
Source
I get this error:
Expression.Error: The name 'ReturnQuery' wasn't recognized. Make sure it's spelled correctly.
Update.
Facepalm! It was a typo. ReturnQuery should be ReturnQueryVar.
However, I would like to leave the question open for the part:
ReturnQueryVar = (optional x) =>
if Parameter1 = "Small"
then " and Product in (1, 2, 3)"
else ""
Does PowerQuery have a syntax for IF:
TextVar = IF(Parameter1 = 'S', 'This', 'That' )
I haven't seen syntax like that, but if you like you can create a function that does that, basically a "container" for the IF statement of Power Query.
For example, you can create a Blank Query called IF with the following contents.
(cond as logical, if_true as any, if_false as any ) =>
if cond then if_true else if_false
Using that function, anywhere it would have similar results and an IF statement.
I am just sharing here a PowerQuery snippet I ended up with. This code allows you to choose with a parameter between two alternate queries - the first for a sample and the other for the full rowset. It allows to download only a small sample of rows from a large table into Power BI Desktop.
let
QueryCode = if Query_Parameter = "Sample"
then
"select 1"
else
"select 2",
Source = Sql.Database(
"MyServer",
"MyDataBase",
[ Query = QueryCode ]
)
in
Source
Prior to that in Power Query Editor > Manage Parameters > Add New Parameter named Query_Parameter with 2 text values as a list: "Sample" and "Full" and based on this parameter the source of the query changes. Just replace "select 1" with anything narrowing your rows like "select top 1000..." or add WHERE condition. "select 2" is your query with full row set.

DAX, Power BI - Concatenate strings

Does anyone know a DAX that could concatenate rows for the example in the image? I want to create a new measure that would englobe all countries together but summing up the repeated ones. BR + BRA would be Brasil.
Example here
I can add up the values for those countries in a DAX which would return numbers, but I am interested in strings specifically. Something like "if in country BR and BRA then Brasil, if in country CH and CHI then Chile".
Thanks!
Create a calculated column that unifies the countries.
all_countries =
SWITCH(
TRUE();
'panelCmd'[country] IN { "BR", "BRA" }; "Brasil";
'panelCmd'[country] IN { "CH", "CHI" }; "Chile";
'panelCmd'[country] IN { "ES", "ESP" }; "Spain";
<...et cetera...>
'panelCmd'[country]
)
Then you can use that column in your table instead of / in addition to country.
Reference on SWITCH(TRUE()...): The Diabolical Genius of “SWITCH TRUE”
Do you mean a measure that concatenate multiple strings into a single comma-delimited string?
If so, you may want to use CONCATENATEX iterator. More specifically, in Power BI Desktop, you can create a measure using the Quick Measure option, and then selecting the "concatenate..." option at the bottom. This will give you a code snippet that does that, and a good starting point.
use & to concatenate strings
Ex:
"String1 " & "String2" & " String3" => String1 String2 String3
Subheading = "for events that occured up to "& FORMAT(TODAY(),"DD") & "th " & FORMAT(TODAY(),"MMMM") & "
Result: for events that occured up to 16th December

Highlighting the search phase IN sql

While it is easy to do replace of the the search text in the code after getting the dataset from an sql with a where clause:
x = x.Replace("SearchText","<span style='color:RED'>SearchText</span>");
I was wondering if there was a way to this IN the SQL.
Select x.Replace("SearchText","<span class='highlight'>SearchText</span>") as x from t where x like '%SearchText%'
or something like that.
The reason I am asking is because I do a:
COALESCE(LastName + ', ' + FirstName, LastName, FirstName) as Name
and I don't want a returned Name field of "Bobbly, Bob" to get two highlighted areas when searching for a LastName that includes "Bob" or a FirstName that includes "Bob" (Noting that first and last names have different search phrases"
Yeah, I could just return the two field separately and join them in code, but I just want to see if it can be done in SQL.
T-SQL includes a Replace Function
REPLACE ( string_expression , string_pattern , string_replacement )
That should do what you need
COALESCE(REPLACE(FirstName,'SearchText1','<span class=''highlight''>' + 'SearchText1' + '</span>')+','
+REPLACE(LastName,'SearchText2','<span class=''highlight''>'+'SearchText2'+'</span>')
,REPLACE(FirstName,'SearchText1','<span class=''highlight''>' + 'SearchText1' + '</span>')
,REPLACE(LastName,'SearchText2','<span class=''highlight''>'+'SearchText2'+'</span>')
,'')

In Scripted Coldfusion Query - why would queryParams not get added?

I have a dynamically generated query, all but one params are optional with one required field.
I thought I would be smart but something very odd happens.
-cfscript
// Standard new query(), set name, datasource etc
query.addParam(value=requiredParam, type=cf_sql_varchar);
sqlStatement = "select ....";
if (optional field 2){
sqlStatement &= "and field like '%?%' ";
query.addParam(value=optionalValue, type=cf_sql_varchar);
}
... optional fields 2,3,4,5 repeats ...
query.execute(sql=sqlStatement);
So when I execute passing only the required field, the query is correct as are the results.
dump shows just the required entry in the sqlParameter (with 2 results)
When I add calls with the optional arguments, only the first (required argument is shown). The optional arguments are NOT shown (in the result dump) and the result set goes to 0 rows. (?? very odd)
I traced it with the debugger, (from cf8 extenstions, cfeclipse, not builder, on CF9 standalone)
The optional field logic was correct, the code was tested and executed.
In the variables pane the params seemed to be added properly but don't show up in the result query, (dump on the result page) only the required one.
I am guessing something odd is happening, but this does not make sense.
Is it possible that all the addParams have to be added together?
Is the like (syntax) the problem?
Why would working with ifs/conditional prevent additional addParams to not work/showup?
Some odd display issue from dump?
Sorry about not providing real code, in a sensitive area.
If you have multiple fields I think it would be best to use the name parameter:
if (optional field 1) {
sqlStatement &= "AND Field LIKE :field1 ";
query.addParam( name="field2", value="%#optionalvalue#%", type=cf_sql_varchar);
}
if (optional field 2) {
sqlStatement &= "AND Field LIKE :field2 ";
query.addParam( name="field2", value="%#optionalvalue#%", type=cf_sql_varchar);
}
Good reading: http://www.bennadel.com/blog/1678-Learning-ColdFusion-9-Using-CFQuery-And-Other-Service-Tags-In-CFScript.htm
Note the bug about putting a space behind the :name in the statement in some cases.
PEBKAC ...
Wrote
if (optional field 2){
sqlStatement &= "and field like '%?%' ";
query.addParam(value=optionalValue, type=cf_sql_varchar);
}
Should have been:
if (optional field 2){
sqlStatement &= "and field like ? ";
query.addParam(value='%#optionalValue#%', type=cf_sql_varchar);
}
Query works properly now, returns correct rows and the parameters used show up in the dump ...

Having issue with inserting a entry into a Table using VB.net/Django/PostgreSQL

I am trying to insert a entry into a table but the server says this
column "Date" is of type date but expression is of type integer at character 131
This is the SQL statement I can also show the VB.net but it is a horrid mess.
INSERT INTO "Inventory_chemicalrecord"("Barcode","Action","Name_id","Building","Qty","Date") VALUES ('IEN0001','ADD',1,'Marcus',1,2013-07-10);
Here is the String that I am passing
mySQLString = "INSERT INTO "&Chr(34)&"Inventory_chemicalrecord"&Chr(34)&"("&Chr(34)&"Barcode"&Chr(34)& ","&Chr(34)&"Action"&Chr(34)& ","&Chr(34)&"Name_id"&Chr(34)& ","&Chr(34)&"Building"&Chr(34)& "," &Chr(34)&"Qty"&Chr(34)& ","&Chr(34)&"Date"&Chr(34)& ") VALUES ("& code & "," &Chr(39)& Action &Chr(39) & "," & Name_id & "," & Building & ","& OriginalQty & "," & CurDate & ");"
Sorry this is the only way I have found to do this if this is the wrong way to do this please inform me.
I have tried
Chr(39)&CurDate&Chr(39)
"'"&CurDate&"'"
and even set
CurDate = Chr(39)&CurDate&CurDate(39)
I keep getting EOF expected and Type & does not match String
Is there a better way to do this?
The error message is very clear.
The date needs to be wrapped in quotes : '2013-07-10'
INSERT INTO "Inventory_chemicalrecord"("Barcode","Action","Name_id","Building","Qty","Date") VALUES ('IEN0001','ADD',1,'Marcus',1,2013-07-10);
should be
INSERT INTO "Inventory_chemicalrecord"("Barcode","Action","Name_id","Building","Qty","Date") VALUES ('IEN0001','ADD',1,'Marcus',1,'2013-07-10');