SSRS Conditional Formatting Switch or IIF - reporting-services

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

Related

SSRS Formula Expression

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
)

How do I do conditional coloring based on a value in the Vega-Lite API

I am trying to conditionally color the text of a heat map in the same style black and white text on this page: Condition
I am looking specifically at the conditional color encoding:
"encoding": {
"text": {"field": "num_cars", "type": "quantitative"},
"color": {
"condition": {"test": "datum['num_cars'] < 40", "value": "black"},
"value": "white"
}
}
I can't seem to get something similar to work in Vega-Lite. My latest version looks like this:
vl.data(weatherData)
.transform(
vl.calculate("monthAbbrevFormat(month(datum.date))").as("month"),
vl.calculate("date(datum.date)").as("day"),
vl.aggregate([{op:"average",
field:"temp_max",
as:"avg_temp"
}]).groupby(["month","day"])
)
.encode(
vl.y().fieldO("month").sort(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]),
vl.x().fieldO("day")
)
.layer(
vl.markRect({tooltip: true, clip: true})
.encode(
vl.color().average("avg_temp").scale({scheme:"redyellowblue", reverse:true})
),
vl.markText({tooltip: true, clip: true})
.encode(
vl.text().average("avg_temp").format(".1f"),
vl.color().condition({test:"datum['avg_temp'] > 26",value:"white"}).value("black")
)
)
.width(1000)
.height(400)
.render()
When I convert that to JSON, I get
"color":{
"condition":{"test":"datum['avg_temp'] > 26", "value":"white"},
"value":"black"
}
which looks the same to my eyes. However, the text resolutely stays black.
I've put the output JSON into the Vega editor, and it also doesn't work there, so the problem isn't limited to my problems with the JavaScript API. It would great if someone could point out where my logic is failing (and also fill me in on the correct syntax in the API as the documentation is sadly lacking in examples).
I figured out my problem. In an earlier version I was computing the average in the encoding. I switched to pre-computing it in the transform, and didn't update the encoding for the text. So it was still
.encode(
vl.text().average("avg_temp").format(".1f"),
vl.color().condition({test:"datum['avg_temp'] > 26",value:"white"}).value("black")
)
The average wasn't changing the values, but it meant that dataum['avg_temp'] wasn't available.
If there is a way to compute the average as part of the test, that would make this a lot cleaner, but I couldn't find a way to do that.

Vega lite: How to change value labels

I could not found out way how to change labels of X axis.
I have this data and I need to show bars which have title taken from field label. Currently bars are aggregated by id and goals is to label bars with label even if the texts are same. I'm confused by examples what to do. Whether I should create layer or some signals. Could someone help me? IMHO this should be trivial, but I did not found anything useful.
{
"id": 15971,
"label": "Click Next to continue",
"result": "Success",
"value": 2
},
{
"id": 15972,
"label": "Click Next to continue",
"result": "No data",
"value": 0
},
There's not really any way to do this in the Vega-Lite grammar, because what you want to do is semantically inconsistent: if you group values by one column, there is no guarantee that the values in another column will match within that grouping.
One option you have is to use labelExpr to define the desired label manually, e.g.
"x": {
"field": "id",
"type": "nominal",
"axis": {"title": "x", "labelExpr": "'Click Next to continue'"},
"scale": {"type": "point"}
},

Can you dynamically set a color scheme and/or range in Vega-lite?

Is it possible dynamically define the color scheme range. For example, I have the below Vega-lite JSON for my color configuration. I would like to input the range below or an entirely different range depending on some condition on the data passed in. Is it possible to set a color range for a variable and dynamically select which one to use?
Also if possible, how would you define the logic to select the appropriate color scheme. The logic is whether some condition on the data (value is present in passed in data) is true. Something like:
IF VALUE IN datum.COL THEN SCHEME1 ELSE SCHEME2
What I am trying to do (maybe there is another way around this) is fix the colors for the FIRST (when sorted) one or two values of the Symbol field (which may or may not be present) and then have the rest default to a standard color range.
Color Scheme 1:
"color": {
"field": "Symbol",
"scale": {
"range": [
"#0b9ddb",
"#c00000",
"#41527a"
]
}
},
Color Scheme 2:
"color": {
"field": "Symbol",
"scale": {
"range": [
"#c00000",
"#41527a",
"#90ee90"
]
}
},
Note, I can get this to work using the following condition but the color in the legend does not change. It sticks to the value in the scale range. Is there a way to get the legend to update to use the color from the condition?
"color": {
"field": "Symbol",
"condition": {
"test": "datum.Symbol == 'Value_0b9ddb'",
"value": "red"
},
"scale": {
"range": [
"#c00000",
"#41527a",
"#90ee90"
]
}
},

CSV, Grouping Products with their parent

I've got a CSV file which will be used to import products into Woocommerce.
It's been generated from Magento and I am having severe trouble grouping parent products with their children (variations). The parent product has the Type "configurable" and the child "simple" and I cannot for the life of me find any unique identifier between the two of them which will allow me to import the children into their parent product.
I notice that each parent product SKU ends with 00, and goes up incremental for each of it's children, 01, 02, 03 and I've noticed that each parent product name is very similar to the child product, with the exception of the added variation attribute such as color etc. - Black, - Blue, - Red etc. being so similar in either SKU or Product name, would it be possible?
I'm thinking this has to be possible using OpenRefine.
Here are some example data, if you've got any idea about a method I can use to combine the two, please don't hesitate to elaborate.
ProductNo,Sku,Type,Product_name,Product_description,Price,CreatedDate,Status,categories
32,VIS00500,configurable,"Spinner II Battery","Batterycapacity: 1650mah",
33,Vis00501,simple,"Spinner II Battery - Black","Spinner II Battery - Black",0.0000,2014-10-02,Enabled,"Shop by Brand>Vision>Batteries and MODs",
And here is another, showing what I hope to achieve:
ProductNo,ParentID,Sku,Type,Product_name,Product_description,Price,CreatedDate,Status,categories
32,VIS00500, ,configurable,"Spinner II Battery","1650mah",14.1800,2014-10-02,Enabled,"Shop by Brand>Vision>Batteries and MODs",
33,Vis00501,32,simple,"Spinner II Battery - Black","Spinner II Battery - Black",0.0000,2014-10-02,Enabled,"Shop by Brand>Vision>Batteries and MODs",
I see you you've provided much more detailed explanations on the Open Refine Google group.
So, could you apply these operations (using "Undo/Redo") on your dataset and tell me if the result is right for you ?
[
{
"op": "core/row-reorder",
"description": "Reorder rows",
"mode": "row-based",
"sorting": {
"criteria": [
{
"errorPosition": 1,
"caseSensitive": false,
"valueType": "string",
"column": "Sku",
"blankPosition": 2,
"reverse": false
}
]
}
},
{
"op": "core/column-addition",
"description": "Create column isparent at index 2 based on column Sku using expression grel:if(value.match(/(.+00$)/).length() > 0, \"parent\", \"\")",
"engineConfig": {
"mode": "row-based",
"facets": []
},
"newColumnName": "isparent",
"columnInsertIndex": 2,
"baseColumnName": "Sku",
"expression": "grel:if(value.match(/(.+00$)/).length() > 0, \"parent\", \"\")",
"onError": "set-to-blank"
},
{
"op": "core/column-move",
"description": "Move column isparent to position 0",
"columnName": "isparent",
"index": 0
},
{
"op": "core/column-addition",
"description": "Create column parent at index 3 based on column Sku using expression grel:if(row.record.cells.Sku.value[0] != value, row.record.cells.Sku.value[0], \"\")",
"engineConfig": {
"mode": "row-based",
"facets": []
},
"newColumnName": "parent",
"columnInsertIndex": 3,
"baseColumnName": "Sku",
"expression": "grel:if(row.record.cells.Sku.value[0] != value, row.record.cells.Sku.value[0], \"\")",
"onError": "set-to-blank"
}
]
If you prefer human explanations :
1° Sort your column "Sku" as text by ascending order (a-z). Reorder rows permanently
2° Create a column "isparent" based on the column "Sku" using the following Grel formula, and move this new column to the begining :
if(value.match(/(.+00$)/).length() > 0, "parent", "")
3° Create a new column "parent_id" based on "Sku" using this Grel formula :
if(row.record.cells.Sku.value[0] != value, row.record.cells.Sku.value[0], "")