How to hide column with expression in SSRS? - reporting-services

I have to hide a column in a report depending on a parameter.
The Parameter (#vExclude) is a text type. It has the following available Options: the Label "None" with Value 0 or Label "Type1" with Value 1 or Label "Type2" with Label 2, it's possible to select multiple values, the default is 0.
The Column (SumCalc) i wanna hide is type money in SQL.
basically the logic is if #vExclude != "none", then show SumCalc in Report.
I've tried the following expressions:
=iif(Parameters!vExclude.Label is ("none"), true, false)
=iif(Parameters!vExclude.Value is ("0"), true, false)
=iif(Parameters!vExclude.Value is ("0"), false, true)
=iif(InStr(Join(Parameters!vExclude.Label,","),"none")=0,true,false)
they all work without error, but do not hide the column correctly. Either SumCalc is always shown or never, but my condition never works.
Following expressions provided an error message:
=iif(Parameters!vExclude.Label = ("none"), true, false)
=iif(Parameters!vExclude.Label = "none", true, false)
=iif(Parameters!vExclude.Value = 0, true, false)
=iif(Parameters!vExclude.Value is 0, true, false)
=iif(Parameters!vExclude.Value = "0", true, false)
=iif(Parameters!vExclude.Value = ("0"), true, false)
=iif(Parameters!vExclude.Value = (0), true, false)
=iif(Parameters!vExclude.Value is (0), true, false)
Does anyone has an idea what I am doing wrong in my expression?

The following should work. Note that we have used the Value as we are checking for umbers here.
=Join(Parameters!vExclude.Value,",").Contains(0)=False
This basically reads "If vExclude does not contain 0" which will return True of it does not contain zero or False if it does contain 0. No need to use an IIF(), just use this as the expression for the Hidden property.

Related

How can i slice an dictionary by key within json data in pyspark?

How can i slice an attribute within an attribute within json data?
Below I have posted an example snip of one business dataset from yelp which is imported into apache spark. I am aware as to how to take a slice of info based on an attribute so far. However how can i slice info of an attribute within an attribute. I have the following code below
rdd.filter(lambda x: x['attributes'].get('Alcohol')).take(5)
This code will return data that has the word 'Alcohol' within 'attributes'
However how can i take a slice of the data to show all attributes which contain 'alcohol' but also 'False' within that part?
I tried this code below posted from another user but this still shows whether it is true or false.
rdd.filter(lambda x: x['attributes'].get('Alcohol', False)).take(5)
I would expect the output to show all the businesses with 'Alcohol' in the 'attributes' and within that to have a 'False'
Hope this makes sense. Thanks
[{'business_id': 'vyutuvybuyb',
'attributes': {'Alcohol': False,
'Music': {'dj': False,
'background_music': True,
'no_music': False,
'karaoke': False,
'live': False,
'video': False,
'jukebox': False},
'RestaurantsGoodForGroups': True,
'Caters': False,
'hours': {'Monday': '11:00-1:00',
'Tuesday': '11:00-1:00',
'Friday': '11:00-1:00',
'Wednesday': '11:00-1:00',
'Thursday': '11:00-1:00',
'Sunday': '11:00-0:00',
'Saturday': '11:00-2:00'}}]

switch statement in ssrs

I have an SSRS report in which I am trying to hide columns based on the select value from a multi-select dropdown. I tried using multiple IIF statements as well as SWITCH CASE but it always throws an error.
Following is my IIF and CASE statements for 2nd and 3rd columns.
=IIF(Parameters!columns.Count >= 1, IIF(Parameters!columns.Value(0) = "3", true, false),
IIF(Parameters!columns.Count >= 2, IIF(Parameters!columns.Value(1) = "3", true, false),
IIF(Parameters!columns.Count >= 3, IIF(Parameters!columns.Value(2) = "3", true, false),
false)))
=IIF(Parameters!columns.Count >= 1, IIF(Parameters!columns.Value(0) = "2", true, false),
IIF(Parameters!columns.Count >= 2, IIF(Parameters!columns.Value(1) = "2", true, false),
false))
=SWITCH(Parameters!columns.Count = 1, IIF(Parameters!columns.Value(0) = "2", false, true),
Parameters!columns.Count = 2, IIF(Parameters!columns.Value(1) = "2", false, true))
=SWITCH(Parameters!columns.Count = 1, IIF(Parameters!columns.Value(0) = "3", false, true),
Parameters!columns.Count = 2, IIF(Parameters!columns.Value(1) = "3", false, true),
Parameters!columns.Count = 3, IIF(Parameters!columns.Value(2) = "3", false, true))
Please help me what I am doing wrong in here
Based on the comments, it appears you are getting an Array Out Of Bounds error which will occur when you attempt to reference a position in an array that does not exist. In this case, your multi-value parameter is considered an array and you are referencing that in the syntax .Value(0). The problem occurs because SSRS will evaluate the entire IIF or SWITCH statement at execution regardless of which value is ultimately returned. This means that when your report has less than 3 values selected, these expression will always be trying to call an array position that does not exist, resulting in the error you are seeing.
So, in order to fix this and check the values as you intend, there is actually a fairly simple workaround that should get you the correct results. The following expression uses JOIN to put all of the parameter's values into a single result with a comma delimiter. You can then use the InStr function which will return a numeric value indicating the position in a string where the search value is first found. In this case, we are searching for the value 3. If 3 is not found, the InStr function will return a value of 0 and any other value will indicate that 3 is present in the joined parameter list.
=IIF(InStr(Join(Parameters!columns.Value, ","), "3") > 0, true, false)

Error occurs when the field is empty during a multiply expression

I came accross a strange problem:
When I use a simple expression like:
=iif(Fields!Length.Value = "", "empty", Fields!Length.Value)
then everything works, and I get my value, or the word "empty" in my report.
If I would change my expression to a sum of 2 times the length, then my "empty" would still appear.
=iif(Fields!Length.Value = "", "empty", (Fields!Length.Value + Fields!Length.Value))
But when I multiply, then my "empty" goes to #Error, While the rest of the data works fine...
=iif(Fields!Length.Value = "", "empty", (Fields!Length.Value * Fields!Length.Value))
Any idea? I find this behavior very, very weird.
Your problem is that IIF evaluates both the true and false results everytime, even if the false result won't be used in the final output. So it's trying to do
'' * ''
when you value is an empty string.
You can fix this by using VAL which will return the numeric value of the string first, like this.
=IIF(Fields!Length.Value = "", "empty", (VAL(Fields!Length.Value) * VAL(Fields!Length.Value)))

Hiding a column based on more than 2 parameters in SSRS

i have columns with imperial values and columns with metric values. i want to hide one or the other based on which region a customer may be from but also if they are part of the company or not. So example if person.value = "Employee" then show imperial and metric but if person.value = "Customer" then CustomerRegion.Value = "Europe" , would be shown metric and CustomerRegion.Value = "North America" would be shown imperial. what would i use to construct an expression to hide one or the other and what would be the easiest way to do it.
You would need to use an IIF statement and add the logic for the various possibilities by nesting multiple IIFs inside each other.
Since you always want to show Imperial to Employees, I would make that the first part of the IIF. For showing and hiding, one column would have one expression while the other would have the same with the TRUEs and FALSEs reversed.
Imperial Hide:
=IIF(PARAMETERS!person.value = "Employee", False,
IIF(PARAMETERS!person.value = "Customer AND PARAMETERS!CustomerRegion.Value = "North America", False,
IIF(PARAMETERS!person.value = "Customer AND (PARAMETERS!CustomerRegion.Value = "Europe" OR PARAMETERS!CustomerRegion.Value = "Asia"), True, True))
Swap the TRUE and FALSE for the Metric column.
Instead of hiding one of the columns, why not use the expression to determine which data to show in a single column? Instead of TRUE or FALSE, you could use the IMPERIAL or METRIC fields.
Apologies Hannover, I've used your answer as a template for mine.
A SWITCH statement would be a better option here IMHO. IIF evaluates all parts of the expression which can be slower whereas SWITCH stops at the first expression that returns TRUE. If more conditions need to be added, nesting IIF's quickly gets messy.
The SWITCH version would be slightly cleaner but definitely more extensible.
Imperial would be
=SWITCH(
Parameters!Person.Value = "Employee", False,
Parameters!Person.Value = "Employee" AND Parameters!CustomerRegion.Value = "Europe", True,
Parameters!Person.Value = "Employee" AND Parameters!CustomerRegion.Value = "North America", False,
True, False)
The last pair of expressions act like an ELSE, it will always return true. Here I set the return to False so by default the column would be shown (Hidden = False)
The metric column would just be the opposite except you would probably want to leave the last pair (the True, False at the end) so the metric column is also shown by default.
This could be made even simpler assuming you only ever have Employee and Customer for person.value as you would not have to check it past the first expression. You can also add multiple checks for regions in a nice consice way rather than put them on separate lines, although you could do this with the IIF answer too..
Something like this.
=SWITCH(
Parameters!Person.Value = "Employee", False,
Parameters!CustomerRegion.Value = "Europe", True,
"North America Asia Somewhere Else".ToLower.Contains(Parameters!CustomerRegion.Value.ToString.ToLower), False,
True, False)
I've used ToLower to make the comparison case insensitive but you could exclude that if you wish.
Thanks for all the insightful answers guys. They all work and give the desired result but i have chosen to go with the "Switch" Statement
I Had structured it in this way for the metric column;
=SWITCH(Parameters!Person.Value = "Employee", False, Parameters!CustomerRegion.value = "North America", True)
And i just changed CustomerRegion.value to "Europe" for the imperial columns. It worked just fine this way. Hope this helps :)

std.json - A bit confused with TRUE, FALSE and NULL values

I was looking over the std.json library as part of program I am working on, and I'm a bit confused about how to get data out of JSONValues whose types are inferred as TRUE, FALSE or NULL.
For example, if I parse the following JSON:
{
"foo" : "bar"
}
I can then extract the string held in the attribute "foo" by doing something like:
auto json = parseJSON("/path/to/json/example.json");
auto foo_attr = json["foo"].str;
But suppose instead that I had JSON like this:
{
"foo" : false,
"bar" : true,
"baz" : null
}
What would I need to do to get at the attribute values of "foo", "bar" and "baz"?
Look at the variable's type.
auto json = parseJSON("/path/to/json/example.json");
bool foo = json["foo"].type == JSON_TYPE.TRUE;
bool bar = json["bar"].type == JSON_TYPE.TRUE;
bool bazIsNull = json["baz"].type == JSON_TYPE.NULL;
Of course, if you expect that values might have other types, you'll need extra checks.