SSRS Formula Expression - reporting-services

can somebody help me make my SSRS Formula the same with my crystal report expression?
Crystal Formula is correct and working as I wanted to but SSRS is giving me wrong result.
Crystal Formula:
if IsNull({OrderDtl.XPartNum}) then {OrderDtl.PartNum}
else ( if IsNull({OrderHed.Calc_CustPartOpts}) then {OrderDtl.PartNum}
else ( select {OrderHed.Calc_CustPartOpts}
case "M": {OrderDtl.XPartNum}
case "S": {OrderDtl.PartNum}
case "O": {OrderDtl.XPartNum}
case "N": {OrderDtl.PartNum}
default: {OrderDtl.PartNum}
)
)
This is the result of the report using CR.
enter image description here
SSRS Formula:
=iif(Fields!XPartNum.Value="", "",
iif(isnothing(Fields!Calc_CustPartOpts.Value), "",
(Switch(UCase(Fields!Calc_CustPartOpts.Value) = "M", Fields!PartNum.Value,
UCase(Fields!Calc_CustPartOpts.Value) = "S", Fields!XPartNum.Value,
UCase(Fields!Calc_CustPartOpts.Value) = "O", "",
UCase(Fields!Calc_CustPartOpts.Value) = "N", "",
True, ""
)
)
)
)
And this is the report using SSRS.
enter image description here
First two items are empty, I can't sort out the cause of this issue, so I thought of using the formula from CR.
Appreciate all the help :)

The logic between the two versions is different, this answer should replicate your CR expression.
This first version simply modifies your structure and changes the check for an empty string in the first line to check for length zero, this will account for NULL/Nothing values too, without the need for two checks.
=IIF(LEN(Fields!XPartNum.Value) = 0, "",
(Switch(UCase(Fields!Calc_CustPartOpts.Value) = "M", Fields!XPartNum.Value,
UCase(Fields!Calc_CustPartOpts.Value) = "S", Fields!PartNum.Value,
UCase(Fields!Calc_CustPartOpts.Value) = "O", Fields!XPartNum.Value,
UCase(Fields!Calc_CustPartOpts.Value) = "N", Fields!PartNum.Value,
True, Fields!PartNum.Value
)
)
)
This version uses SWITCH only to simplify things.
=SWITCH(
LEN(Fields!XPartNum.Value) = 0, "",
UCase(Fields!Calc_CustPartOpts.Value) = "M" OR UCase(Fields!Calc_CustPartOpts.Value) = "O", Fields!XPartNum.Value,
True, Fields!PartNum.Value
)

Related

Update values in a dash datatable column based on user input

I'm doing a dash application. This is my first one.
I have a dropdown (id='demo-dropdown') and a dash_table.DataTable
tab : dash_table.DataTable = dash_table.DataTable(
id='datatable-interactivity',
columns=[
{"name": 'systemName', "id": 'systemName', "deletable": False, "selectable": False},
...
{"name": 'x', "id": 'x', "deletable": False, "selectable": False, "hideable": True, "type": "numeric"},
{"name": 'y', "id": 'y', "deletable": False, "selectable": False, "hideable": True, "type": "numeric"},
{"name": 'z', "id": 'z', "deletable": False, "selectable": False, "hideable": True, "type": "numeric"},
...
{"name": 'distance', "id": 'distance', "deletable": False, "selectable": False, "type": "numeric"},
],
data=df.to_dict('records'),
editable=False,
filter_action="native",
sort_action="native",
sort_mode="multi",
column_selectable=False, # "single",
row_selectable=False, # "multi",
row_deletable=False,
selected_columns=[ ],
selected_rows=[ ],
page_action="native",
page_current=0,
page_size=100,
)
The dropdown specifies a location (x0,y0,z0), and I want to fill the distance column with regular euclidean distance values from that point. For the moment, I'd be happy to increment the values in the distance column by 5 when the user clicks the dropdown.
Here's my callback:
#app.callback(
[dash.dependencies.Output('datatable-interactivity', 'data'),
dash.dependencies.Output('datatable-interactivity', 'columns')],
[dash.dependencies.Input('demo-dropdown', 'value')])
def update_output(value):
columns = [{"name": 'distance', "id": 'distance'}]
nrows = df.shape[ 0 ]
for ind in df.index:
x1: float = df.at[ind, 'x']
y1: float = df.at[ind, 'y']
z1: float = df.at[ind, 'z']
dis: float = math.sqrt((x - x1) ** 2 + (y - y1) ** 2 + (z - z1) ** 2)
df.at[ind, 'distance'] = dis
return [df['distance'].to_dict(), columns] #tried "records" "rows"
My problem seems similar to How can we create data columns in Dash Table dynamically using callback with a function providing the dataframe - but I can't seem to make it work.
The error message I get is:
Invalid argument `data` passed into DataTable with ID "datatable-interactivity".
Expected an array.
Was supplied type `object`.
Value provided:
{
"0": 37.0625,
"1": 94.53125,
"2": 62.03125,
"3": 33.65625,
"4": 33.65625,
...
"185": 63.59375
}
at propTypeErrorHandler (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/dash_renderer.v1_4_1m1588701826.dev.js:37662:9)
at CheckedComponent (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/dash_renderer.v1_4_1m1588701826.dev.js:32489:77)
...
I've tried various combinations of lists and dicts for the return with no luck. Also, I think, but am not sure, that updating the dataframe in place is the right thing to do.
(Just to sum up - this is what I think I'm doing: notifying the view that data in the model has changed by returning a list with two dicts, the first one has row indices and the new values, and the second identifies the column(s) that are changed.)
Thanks!
Update
As far as I can tell, changing the last two lines of the callback to the following works:
_cols = [{"name": i, "id": i} for i in df.columns]
return df.to_dict('records'), _cols
i.e. replacing all the values in the table, instead of just the last column.

Convert record with Power Query and JSON

I'm using Power Query on Excel 2013 to convert an huge JSON file (more than 100Mb) to plain excel sheet.
All the fields except one are converted correctly but there is one specific field that is recognized as record. All other fields have a fixed text value or values separated by comma, so the conversion is pretty easy, this field inside has a JSON record structure so "Field" : "Value".
This is an extract of the file:
{
"idTrad": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"images": {
"1": "SE1.JPG",
"2": "SE2.JPG"
},
"date": "2018-09-22",
"category": "MD",
"value": "Original text",
"language": "IT",
"contexts": [
""
],
"label": "Translated text",
"variantes": "1,23,45,23,32,232,2315,23131",
"theme": [
"XX_XXX"
]
}
The problematic field is "images" because it's recognized as a record, in the resulting table I have this situation:
[1]: https://i.stack.imgur.com/EnHow.png
My query so far is:
let
Source = Json.Document(File.Contents("filename.json")),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Column1 développé" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"value", "contexts", "theme", "variantes", "category", "label", "language", "idTrad","images", "date"}, {"Column1.value", "Column1.contexts", "Column1.theme", "Column1.variantes", "Column1.category", "Column1.label", "Column1.language", "Column1.idTrad","Column1.images", "Column1.date"}),
#"Valeurs extraites" = Table.TransformColumns(#"Column1 développé", {"Column1.contexts", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Valeurs extraites1" = Table.TransformColumns(#"Valeurs extraites", {"Column1.theme", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
#"Valeurs extraites1"
I would like to have in the images field a text rappresentation of the record so something like "1: SE1.JPG, 2: SE2.JPG", any ideas?
Sure, you can even do it in one step! If you convert a record to a table (Record.ToTable) it will create a table where the names of the fields in your record are in a column called "Name" and the values are in a column called "Value". This way you get your "1", "2", etc from the json file. From there you can just combine the columns into the text you want and convert and combine a list like you did in the rest of your columns.
= Table.TransformColumns(#"Valeurs extraites1",{"Column1.images",
each
Text.Combine(
Table.ToList(
Table.CombineColumns(
Record.ToTable(_)
,{"Name", "Value"},Combiner.CombineTextByDelimiter(": ", QuoteStyle.None),"Merged")
)
, ", ")
})
I wouldn't think Record.ToTable localizes it's column naming , but maybe test it with just converting the record to a table first to see what it does.
Table.TransformColumns(#"Valeurs extraites1",{"Column1.images",each Record.ToTable(_)})

Regex: Parsing between beginning and end of two different Instance Identifiers in JSON

I've been exhaustively searching for a way to search between something like in this case "dog123", and "cat123", so that I'll be able to use an integration platform to remove them as needed. At first I thought it would need to be something along the lines of using \"dog123\"\,[a-z0-9A-Z",_]* and then some other stuff to explain the end boundary, but i'm completely lost at this point. Does anyone have any suggestions? The end result is again to just remove every single line of text between "cat123",
{
"items": [
{
"tableName": "Table0",
"count": 2,
"columnNames": [
"dog123,
"referenceNumber",
"account_id",
"first",
"last",
"street",
"city",
"name",
"name",
"postalCode",
"address",
"number",
"dob",
"lookupName",
"address",
"lookupName",
"lookupName",
"lookupName",
"lookupName",
"awareness_date",
"patient_description",
"date_of_issue",
"lookupName",
"cat123",
"insertion_site",
"lot_number",
You didn't specify the programming language, but to replace everything between "dog123", and "cat123" using php, you can try:
$new_json = preg_replace('/"dog123",.*"cat123",/sim', '"dog123","cat123",', $old_json);
print $result;
for python use:
import re
new_json = re.sub('"dog123",.*"cat123",', '"dog123","cat123",', old_json, 0, re.IGNORECASE | re.DOTALL | re.MULTILINE)

How to Extract a Word and insert a string containing the word into an existing longtext field?

I'm nervously migrating and updating a MySQL database and for each record I need some help to achieve the following:
Extract the last word from the 'Name' column of a record
Encapsulate the extracted word in a string.
Replace the first character in the 'elements' column (longtext) with the new string.
Example:
The 'Name' column contains the following data:
Andrew Brewer
The extracted word should be encapsulated in a string to look this:
{
"0152cbf9-2bab-48dc-81e3-82d7b1b505ec": {
"0": {
"value": "Brewer"
}
},
The current 'elements' column begins with the following data:
{
"540aa2ad-9a8d-454d-b915-605b884e76d5": {
"file": "images\/profile-male\/ANDY_B_PROFILE.jpg",
"title": "",
"link": "",
"target": "0",
"rel": "",
"lightbox_image": "images\/profile-male\/ANDY_B_PROFILE.jpg",
"spotlight_effect": "",
"caption": "",
"width": 833,
"height": 1163
},
etc...
We need the new 'elements' column to look like this (assuming that it's easier to replace the first character in a field than to insert it):
{
"0152cbf9-2bab-48dc-81e3-82d7b1b505ec": {
"0": {
"value": "Brewer"
}
},
"540aa2ad-9a8d-454d-b915-605b884e76d5": {
"file": "images\/profile-male\/ANDY_B_PROFILE.jpg",
"title": "",
"link": "",
"target": "0",
"rel": "",
"lightbox_image": "images\/profile-male\/ANDY_B_PROFILE.jpg",
"spotlight_effect": "",
"caption": "",
"width": 833,
"height": 1163
},
etc...
No special allowances for spaced surnames etc. is required
Any and all help gratefully received.
What would the query code be to achieve the above?
I'm a designer with HTML/CSS/jQuery skills but an absolute SQL novice and I haven't gotten very far today, despite spending 12 hours on this.
I've had intermittent results with obtaining the last name as some of the names have trailing spaces and are resisting the trim command. Maybe they're not spaces but another type of whitespace? In any case the idea was to reverse the string, find the first space, trim and reverse again, which is succeeding as far as it goes.
SELECT RTRIM(`name`),
REVERSE(SUBSTRING(REVERSE(`name`), 1, LOCATE(' ', REVERSE(`name`)) - 1)) AS LastName
FROM `artist`;
The next step would be to concatenate the string start+LastName+end then replace the first character of the 'elements' column but I have no idea how to do this.
If I'm in the wrong place to ask this type of question, please feel free to close this and I'll resort to editing the database manually.

SSRS Conditional Formatting Switch or IIF

I currently have the following 2008 SSRS Report and I want to conditionally format background of the columns based on some logic.
I have three columns and two of which I would like to change the background color.
Columns "Current Risk Level", "Trend", "Tolerance". Each contains rows of either Low, Moderate, Medium, High, Very High
For column "Current Risk Level" I would like Low="Green",Moderate="Blue",Medium="Yellow",High="Orange",Very High="Red"
For column "Tolerance" I would like
Low="Red",Moderate="Orange",Medium="Yellow",High="Blue",Very High="Green"
I don't know how to set up a SWITCH or IIF function to accomplish this.
Any help would be really appreciated!
To dynamically change the color of a text box goto properties, goto font/Color and set the following expression
=SWITCH(Fields!CurrentRiskLevel.Value = "Low", "Green",
Fields!CurrentRiskLevel.Value = "Moderate", "Blue",
Fields!CurrentRiskLevel.Value = "Medium", "Yellow",
Fields!CurrentRiskLevel.Value = "High", "Orange",
Fields!CurrentRiskLevel.Value = "Very High", "Red"
)
Same way for tolerance
=SWITCH(Fields!Tolerance.Value = "Low", "Red",
Fields!Tolerance.Value = "Moderate", "Orange",
Fields!Tolerance.Value = "Medium", "Yellow",
Fields!Tolerance.Value = "High", "Blue",
Fields!Tolerance.Value = "Very High", "Green")