Using SUM with a switch function in Report builder 3.0 - reporting-services

I have a column of data called Date and I am using that to perform a switch. Basically the figure needs to be 120 on a weekday and 0 on a weekend so I have used.
=SWITCH
(Weekday(Fields!Date.Value) = "1", "0",
Weekday(Fields!Date.Value) = "2", "120",
Weekday(Fields!Date.Value) = "3", "120",
Weekday(Fields!Date.Value) = "4", "120",
Weekday(Fields!Date.Value) = "5", "120",
Weekday(Fields!Date.Value) = "6", "120",
Weekday(Fields!Date.Value) = "7", "0"
)
Which works great. However I also want a Total at the bottom of the sheet. I (somewhat naively) tried adding
=SUM( ... )
to the expression but that resulted in an #Error in the textbox. I also tried
=SUM(ReportItems!Textbox85.value)
and that didn't even run throwing the error
The Value expression for the textrun
'Textbox84.Paragraphs[0].TextRuns[0]' uses an aggregate function on a
report item. Aggregate functions can be used only on report items
contained in page headers and footers.
So my question is how do I sum up this switch function or do I need to rethink this? I guess functionally all I really need is count of the total weekdays so far "this" month (that stays accurate no matter what month is picked using the date parameters). I can then * that number by 120.

So I came at it from a different angle and tried a SQL based solution. I added a column with the code
,CASE
WHEN
DATEPART(dw,convert(date,format(dateadd(hh,1,[Start Time]),'dd/MM/yyyy'),103)) in (1,7)
THEN 0
ELSE 1
End as [weekday]
Then used
=Fields!weekday.Value*120
in my textbox and
=Sum(Fields!weekday.Value, "DataSet1")*120
in my total. Got the desired results.

Related

SQl query help in grouping

An SQL table schema,
time, country, activer_users
If I just want to show the total number of active users over time, Below simple slect wil do that
SELECT time, sum(active_users) as activer_users GROUP BY time ORDER BY time
returned data will be like,
[{
"time": 1585878969,
"active_users": 2300
},....]
If I want active_users over time by country, then
SELECT time, country, sum(active_users) as activer_users GROUP BY time ORDER BY time, country
returned data will be like,
[{
"time": 1585878969,
"active_users": 1300,
"country": "India"
}, {
"time": 1585878969,
"active_users": 1000,
"country": "China"
}....]
I want data in the below format,
[{
"time": 1585878969,
"India": 1300,
"China": "1000"
}....]
Is this possible, to create dynamic columns from the value of a field and its value based on another field..
if suchthing is possible, what should be the query for that
Other helpful users may correct me, but I think is not possible altering MySQL responses like this. MySQL always responds in a COLUMN-VALUE way, so you would have to create a column e.g. "China" and store this data in there to get a native response like this.

Add more values to expression using IIF

I am looking for help updating an expression used in a SSRS report.
The current expression is something like this:
=IIF(Fields!Type.Value = "TKT", "Ticket No.",
IIF(Fields!Type.Value = "CUN", "Customer Number",
IIF(Fields!Type.Value = "ANM", "Account Number",
IIF(Fields!Type.Value = "CID", "Client ID", ""))))
We have added a few more "Types"
So for Type "TKT" now we have: "TKT1", "TKT2". For Type "CUN", now we have "CUN1", "CUN2, and so on for the last 2.
I am not familiar with how when using an IIF function, multiple values can be specified (similar to an IN operator).
If anyone could share some light regarding how this is done, that would be awesome.
Thank you for your help in advance.
You would probably be better off converting this expression to a SWITCH statement before this thing gets out of hand. A SWITCH accepts as many conditional and result pairings as you need to add. The following expression allows you to add as many checks as you need and the final pairing true,"" simply sets any that don't match the switch statement to a blank value.
=SWITCH(Fields!Type.Value = "TKT1", "Ticket No.",
Fields!Type.Value = "TKT2", "Ticket No.",
Fields!Type.Value = "CUN1", "Customer Number",
Fields!Type.Value = "CUN2", "Customer Number",
Fields!Type.Value = "ANM", "Account Number",
Fields!Type.Value = "CID", "Client ID",
[add additional pairings here],
true, "")
An additional solution would be to use the Contains keyword in SSRS. This would search the string to find a particular substring. You could simply modify each conditional to the following which would return true if the field contains that substring.
Fields!Type.Value.Contains("TKT")

Replace different values with specific text in report builder

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

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 :)

Check if JSON string in Orbeon repeating grid contains a specific value

Working with the repeating grids through the form builder.
I have a custom control that has a string value represented in json.
{
"data": {
"type": "File",
"itemID": "12345",
"name": "Annual Summary",
"parentFolderID": "fileID",
"owner": "Owner",
"lastModifiedDate": "2016-10-17 22:48:05Z"
}
}
In the controls outside of the repeating grid, i need to check if name = "Annual Summary"
Previously, i had a drop down control and using Calculated Value $dropdownControl = "Annual Summary" it was able to return true if any of the repeated rows contained the value. My understanding is that using the = operator, it will validate against all rows.
Now with the json output of the control, I am attempting to use
contains($jsonStringValue, 'Annual Summary')
However, this only works with one entry and will be null if there are multiple rows.
2 questions:
How would validate whether "Annual Summary" (or any other text) is present within any of the repeated rows?
Is there any way to navigate the json or parse it to XML and navigate it?
Constraint:
within the Calculated Value or Visibility fields within form builder
manipulating the source that is generated by the form builder
You probably want to parse the JSON string first. See also this other Stackoverflow question.
Until Orbeon Forms 2016.3 is released, you would write:
(
for $v in $jsonStringValue
return converter:jsonStringToXml($v)
)//name = 'Annual Summary'
With the above, you also need to scope the namespace:
xmlns:converter="org.orbeon.oxf.json.Converter"
Once Orbeon Forms 2016.3 is released you can switch to:
$jsonStringValue/xxf:json-to-xml()//name = 'Annual Summary'