I'm encountering an issue while develloping some report on RB.
I have a tablix that where the columns are the hours of the day, and the rows are different products. I also have a parameter with 3 values (AM, PM, NIGHT).
The point here is that if the parameter is set to AM, the tablix only display columns from 6 to 12, if it's set to PM, the tablix display from 12 to 18,...
I can display time intervals (6 to 12) by using filter where i tell him "Hour" IN "6, 7, 8, 9, 10, 11, 12". But it doesn't work when i set the filter value as following:
Expression: =Cstr(Fields!ProdHour.Value)
Operator: IN
Value:
=iif(join(Parameters!Shift.Value) = "AM",
"6, 7, 8, 9, 10, 11, 12" ,
iif(join(Parameters!Shift.Value) = "PM",
"13, 14, 15, 16, 17, 18",
iif(join(Parameters!Shift.Value) = "NIGHT",
"19, 20, 21, 22, 23, 0",
false)
)
)
Do you have any idea how I could solve this? Tried to change every number in Integer but didn't work...
I found a working solution:
I had to create 2 new fields in the same dataset as the table,I named those fields "ShiftStart" and "ShiftStop".
ShiftStart value : =iif(join(Parameters!Shift.Label)="AM","6",iif(join(Parameters!Shift.Label)="PM","12",iif(join(Parameters!Shift.Label)="NIGHT","0","0")))
Same with ShiftStop but with others values (12,18,0). So with those 2 data, when I pick "AM", ShitStart= 6 and ShiftStop=12, now i can create a filter to display columns where [Hour] is between [ShiftStart] and [ShiftStop].
Simple as that!
Thanks guys for you help! Sorry I can't Uptvote you, not enough reputation :(
I would suggest change the binding of your parameter like (ID,Value) see screen shot below
Now you can use the expression to get selected value
=Parameters!ReportParameter1.Value
You can also use below query to bind your dropdown, if don't want to hard code
Select ID,Value From
(Values('6,7,8,9,10,11,12','AM'),
('13,14,15,16,17,18','PM'),
('19,20,21,22,23,0','Night'))
tblTime(ID,Value)
I think that is what you are looking for
I would abandon using the In operator in the SSRS Filter Expression. I have only had universally bad experiences with Filters using any operator apart from "=" and also issues with datatypes.
My preference would be to filter this data out in the dataset query using SQL. However that is not the question.
In SSRS Filters, from hard experience, I now only always set datatype: "Boolean", operator: "=" and Value: "True". Then your challenge is to code an expression that only returns True for the rows you want to keep.
That could be something like:
=Iif ( ( Parameters!Shift.Value = AM and ("6,7,8,9,10,11,12").Contains(Fields!Hour.Value) )
Or ( ...
Is the Shift parameter multi-select?
Related
I hope someone can assist or point me in the right direction
I have a report that contains Fields!District.Value, If this value = "area 1" then i would like to add 60 days to the Field!Date.Value
Obligatory "I'm still learning" SSRS and I have tried the following with no success;
=IIf(Fields!District.Value="North Lanarkshire","DateAdd("d", 60, Fields!Date.Value)"
I'm assuming it's placement of a , or )
thanks in advance for your help :)
There are a couple of mistake here. Let's break it down.
To start with the IIF function syntax can be thought of like this..
IIF([Expression to evaluate to true or false], [expression to return if true], [expression to return if false])
So your first expression Fields!District.Value="North Lanarkshire" is fine, this will return true or false.
Next expression, what to return if true is close but not correct. "DateAdd("d", 60, Fields!Date.Value)". There is no need for the outer quotes and instead of "d" you should use DateInterval.Day so this should end up being DateAdd(DateInterval.Day, 60, Fields!Date.Value).
Finally we need something to return if the result is false (i.e. District is not "North Lanarkshire"). I'll assume you just want the original date column's value returned here so we can just use Fields!Date.Value
So, the final expression should look like this.
=IIF(Fields!District.Value="North Lanarkshire", DateAdd(DateInterval.Day, 60, Fields!Date.Value), Fields!Date.Value)
I need the ids of a table but #pluck is not fast enough because there are too many records.
The thing is that I would like to get them in a string directly from mysql instead of get any Array or ActiveRecord::Relation
[1, 2, 3] => "1,2,3"
There is no group_concat in Rails, so I just asked via sql. Example:
sql = User.select("GROUP_CONCAT(users.id)").to_sql
ActiveRecord::Base.connection.exec_query(sql)
The thing is that I don't know why but it does not return all the ids of the table, but just some of them.
Any idea why is not returning all of them or how can I achieve it in a different way?
Apparently the result is truncated to the maximum length that is given by the group_concat_max_len.
Maybe you could increase that value. Follow this answer to get more information:
https://stackoverflow.com/a/5545904/8195530
You could just call it like this
sql = "select GROUP_CONCAT(id) from users"
data = ActiveRecord::Base.connection.exec_query(sql)
# #<ActiveRecord::Result:0x0000560661a2b7d8 #columns=["ids"], #rows=[["41,40,38,42,39,43,45,44"]], #hash_rows=nil, #column_types={}>
then you can get the data as ids with
ids = data['ids'].split(',').map(&:to_i)
# [41, 40, 38, 42, 39, 43, 45, 44]
In MS Access , I have a field by name "TargetDays" that has values like "0", "13", 20", "6", "1", "9", ".""2", "28"
I want them to be sorted as
., 0, 1, 2, 6, 9, 13, 20, 28
I tried doing ORDER BY val(TargetDays)
But this sorts sometimes as ., 0, 1, 2, 6, 13, 20, 28. But other times it sorts as 0, ., 1, 2, 6, 13, 20, 28. The problem is coming with "." and "0".
Could someone please tell me a solution to sort in the intended order (as mentioned above)?
That happens because Val(".") and Val("0") both return 0, so your ORDER BY has no way to distinguish between those 2 characters in your [TargetDays] field ... and no way to know it should sort "." before "0".
You can include a secondary sort, based on ASCII values, to tell it what you want. An Immediate window example of the Asc() function in action ...
? Asc("."), Asc("0")
46 48
You could base your secondary sort on that function ...
ORDER BY val(TargetDays), Asc(TargetDays)
However, I don't think you should actually need to include the function because this should give you the same result ...
ORDER BY val(TargetDays), TargetDays
I have a table that will return a number and i need to convert it into a text label
20 = Entered, 30 = Returned, 200 = Cancelled, 220 = Complete, 300 = Deleted
I want these to show in my report as simply 'Complete' etc.
Im able to use the replace function to get one value to show correctly in the report:
=Replace(Fields!status.Value,"220","Complete")
But i cant work out how to do this for each possible number that will show in this column
Best way would likely be modifying the query with a CASE statement as mentioned, if you are able to do that. But if not, a cleaner alternative to the nested Replaces would be to simply use a Switch statement:
=Switch(
Fields!Status.Value = "20", "Entered",
Fields!Status.Value = "30", "Returned",
Fields!Status.Value = "200", "Cancelled",
Fields!Status.Value = "220", "Complete",
Fields!Status.Value = "300", "Deleted"
)
This is not the most efficient way to do this, but it's a quick fix:
=Replace(Replace(Replace(Replace(Replace(Fields!status.Value,"220","Complete"), "200","Cancelled"),"300","Deleted"),"20","Entered"),"30","Returned")
A better way would be to modify your DataSet query to replace the numbers with a CASE statement. See this documentation:
https://learn.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql
I am trying to add an parameter that will allow the user to filter by unit Cost. I.e. If for parameter Unit cost, User select "All Costs", it will not perform any filter and will show all items. However, if for the parameter Unit cost, the user selects "Greater than 0" it would only display items that have unit cost > 0.
I have declared the parameter with two available values "U" and A".
However, what would the Parameter condition look like? I tried adding the condition which was =IIF(Parameter!Text.Value = "U", UnitCost, NOTHING) > 0.
This doesn't seem to be working though. Can anyone provide suggestions as to how this would be done.
You can use an expression to determine if a row should be filtered or not based on the parameter selected value.
Add a new Filter condition in your tablix and use these settings and expressions:
In Expression textbox use:
=Switch(
Parameters!Text.Value = "All", "Include",
Parameters!Text.Value = "U" AND Fields!UnitCost.Value > 0, "Include",
Parameters!Text.Value = "A" AND Fields!UnitCost.Value > 10, "Include",
true, "Exclude"
)
In the Value textbox use:
="Include"
Note your parameter should have an available value as conditions to filter you need.
In this case I use A parameter value to filter the UnitCost values greater than 10 and U value to filter UnitCost values greater than 0. Customize to meet your requeriment.
Let me know if this helps.