BackgroundColor expression - sql-server

I created a Base_Rent_Variance Calculated field that works like it should:
=IIF(Fields!CurrNrmRent.Value = 0 and Fields!PriorNrmRent.Value > 0, "Review", IIF(Fields!PriorNrmRent.Value = 0 and Fields!CurrNrmRent.Value > 0, "Review", IIF(Fields!CurrNrmRent.Value > 0 and Fields!PriorNrmRent.Value > 0, (Fields!CurrNrmRent.Value-Fields!PriorNrmRent.Value)/IIF(Fields!PriorNrmRent.Value = 0, 1, Fields!PriorNrmRent.Value), nothing)))
I am trying to create a BackgroundColor expression so that if Base_Rent_Variance >= 15% or <= -15%, the background color is red, and if it equals Review the color is red. The expression I created is filling the background red correctly for the 15% variances but not the Review. My expression is below. What am I doing wrong?
=IIF(Fields!Base_Rent_Variance.Value >= .15 or Fields!Base_Rent_Variance.Value <= -.15, "Red",iif(RTRIM(Fields!Base_Rent_Variance.Value) = "Review","Red","White"))

This is likely an issue with your datatypes. You're attempting to store both numeric and string types in the same field. I would use a conversion to be sure you have the correct datatypes. This expression should handle the mismatched datatypes.
=IIF(CDbl(Fields!Base_Rent_Variance.Value) >= .15 or CDbl(Fields!Base_Rent_Variance.Value) <= -.15,
"Red",
IIF(TRIM(CStr(Fields!Base_Rent_Variance.Value)) = "Review","Red","White"))
Another option to try is using the InStr function like the following.
=IIF(CDbl(Fields!Base_Rent_Variance.Value) >= .15 or CDbl(Fields!Base_Rent_Variance.Value) <= -.15,
"Red",
IIF(InStr(CStr(Fields!Base_Rent_Variance.Value), "Review"),"Red","White"))
Based on the comment below, let's try this one with a switch statement. The following switch statement will evaluate the first expression, set the cell red if true, check the second expression, set the cell red if true, and finally set anything left to white.
=SWITCH(CDbl(Fields!Base_Rent_Variance.Value) >= .15 or CDbl(Fields!Base_Rent_Variance.Value) <= -.15, "Red",
InStr(CStr(Fields!Base_Rent_Variance.Value), "Review"),"Red",
true, "White")

You can also use me.Value in colour expressions.
For example:
=iif(me.Value = "Review" OrElse me.Value >= 0.15 OrElse me.Value <= -0.15, "Red", "NoColor")
This means you don't have to recalculate your values each time, or keep track of changes in several locations if the calculations change.

Related

How can I use my plotted data in further calculations?

So I have this code that draws zigzag-alike line
indicator("Custom zigzag", overlay=true)
bullish(at) => open[at] < close[at]
bearish(at) => open[at] > close[at]
break_up() =>
if close != open
at = 1
while close[at] == open[at]
at += 1
if bearish(at) and bullish(0)
true
else
false
else
false
break_down() =>
if close != open
at = 1
while close[at] == open[at]
at += 1
if bearish(0) and bullish(at)
true
else
false
else
false
u = break_up()
d = break_down()
plot(u?open[0] : d?open[0] : na, color = color.fuchsia, linewidth = 1, style = plot.style_line, offset=0)
I want to use the result in some further calculations, but I dont get it, how can I put the whole u?open[0] : d?open[0] : na in an array?
Roughly pushing values to an array variable leads to recalculation on each bar, IMO.
Or can I access somehow my own previous plot, since custom script call is not possible?
There are two ways to do it depending on do you want na values as it is or previous calculated values in place of na. You can save the whole thing in a variable and then use that to calculate anything like sma etc. First way
//Keeping na value
val=u?open[0] : d?open[0] : na
s=ta.sma(val,10)
plot(s)
Second way
//Replacing na values with previous values
var val=open[0]
val:=u?open[0] : d?open[0] : val[1]
s=ta.sma(val,10)
plot(s)

Why is a random part of the code highlighted?

We have an online editor made by monaco-editor, here is the link: https://v3.10studio.tech/#/formula-editor-addin?app=formula-editor-addin. Users could enter an Excel formula like =1+2+3+4+5, then click on the Format button to see the formatted formula.
What is odd is that, after clicking on Format button, a random part of the formula is often highlighted in gray:
Does anyone know what may be the cause?
PS: The current options setting are as follows:
const monacoOptions: monacoEditor.editor.IEditorConstructionOptions = {
lineNumbers: 'off',
selectionHighlight: false,
glyphMargin: false, //left side,
lineDecorationsWidth: 0, // width between line number and content,
renderIndentGuides: false, // no indent guide lines
minimap: { enabled: false },
};
When you set the value of the model ie editor.getModel().setValue('FORMATTED-CODE') you should have to set the position of the cursor manually.
The selection is actually not random. Monaco will select all the extra texts you have added. For example -
Before : 1+2+3+4+5 - here last position is line 1 column 10
Format: 1 + 2 + 3 + 4 + 5 - here last position is line 1 column 18
So the extra text + 4 + 5 is selected, it means column 11 to 18 is selected
To set the position of the cursor at where it was before
const pos = editor.getPosition()
editor.getModel().setValue('FORMATTED-CODE')
editor.setPosition(pos)
To set the position of the cursor at Line 1 Column 1
editor.getModel().setValue('FORMATTED-CODE')
editor.setPosition({ lineNumber: 1, column: 1 })
To set the position of the cursor at last (using offset)
const formatted = 'FORMATTED-CODE'
const offset = formatted.length
const pos = editor.getModel().getPositionAt(offset)
editor.getModel().setValue(formatted)
editor.setPosition(pos)
You can also set selection
editor.setSelection({
startLineNumber: 1,
startColumn: 1,
endLineNumber: 1,
endColumn: 5,
})
For more informations you can follow these APIs -
setPosition - To set cursor position
setSelection - To set selection
setSelections - To set multiple positions & selections

Qlikview - multiple if in script

I have table:
I want to make in script to load data this:
(if((color = 'blue' or color = 'green' or color = 'red') and place = 'A','GROUP A') or
if((color = 'yellow' or color = 'red' or color = 'blue') and place = 'B','GROUP B')) as allPl
but when create list my allPl is empty.
Any idea?
The most simple solution, I think, will be
If(mixmatch(id,'blue','green','red') and place='A','Group A',
If(mixmatch(id,'blue','green','yellow') and place='B','Group B')) as allPl
You need to nest the if statements to get the result.
if( condition1 = true, result1,
if(condition2 = true <at this point condition1 = false>, result2 ...
For your case:
if( color = 'blue'
or color = 'green'
or color = 'red','GROUP A',
if( color = 'yellow'
or color = 'red'
or color = 'blue','GROUP B')
) as allPl
The script above will produce the following result:
But i'm not sure that this is the result you want. As you can see from the image above only the yellow value will have GROUP B assigned using this approach.
Leave a comment is this is the case
You can also use this solution.
map_allPl:
mapping
load
color & '##separator##' & place AS IN
,allPl AS OUT
inline
[color,place,allPl
blue,A,GROUP A
green,A,GROUP A
red,A,GROUP A
yellow,B,GROUP B
red,B,GROUP B
blue,B,GROUP B];
table:
load
*
,applyMap('map_allPl',color & '##separator##' & place,'nd') AS allPl
inline
[id,color,place
1,blue,A
2,green,A
3,red,A
4,yellow,B
5,red,B
6,blue,B
];
you can try with match() or wildmatch() or mixmatch() to reduce your expression.
try like,
if(match(color,'blue','green','red') and place='A','Group A',
if(match(color,'yellow','red','blue') and place='B','Group B')
) as appPl
Regards,

Microsoft.Office.Interop.PowerPoint Chart - with broken y-Axis

We are using the Interop PowerPoint Chart type to generate an area chart as shown in the figure. We need the "broken" y-Axis. We dont want the break on the bars itself - we need the break only on the y-Axis. But are unable to find a property or a method to achieve this.
This a winforms application. Would really appreciate some pointers...
Accidentally stumbled upon this question, and I let my curiosity takes over.
I got how it's done taken from this site.
I'm using example data from above site for this walkthrough.
The step roughly like this:
Assign cut value for data separation. Separate data using a cut value (I use cut value 7,500,000 for the example)
This is data separation from the example (above is the original, below is the separated):
May June July
London 1,234,565 1,452,369 1,478,852
Paris 2,363,645 34,568,876 5,562,413
Madrid 32,645,254 3,211,654 5,857,421
Brussels 5,914,753 5,544,221 3,620,015
Lisbon 5,824,676 4,541,258 4,015,876
Munich 2,501,478 6,325,698 4,569,872
May June July Column4 Column5 Column6
London 1,234,565 1,452,369 1,478,852 0 0 0
Paris 2,363,645 7,500,000 5,562,413 0 34,568,876 0
Madrid 7,500,000 3,211,654 5,857,421 32,645,254 0 0
Brussels 5,914,753 5,544,221 3,620,015 0 0 0
Lisbon 5,824,676 4,541,258 4,015,876 0 0 0
Munich 2,501,478 6,325,698 4,569,872 0 0 0
Assign Column4, Column5, and Column6 into secondary axis.
Dim c As Microsoft.Office.Interop.PowerPoint.Chart
Dim sc As Microsoft.Office.Interop.PowerPoint.SeriesCollection = Nothing
Dim sr As Microsoft.Office.Interop.PowerPoint.Series = Nothing
sc = c.SeriesCollection
For i = 4 To sc.Count
sr = sc.SeriesCollection(i)
sr.AxisGroup = Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlSecondary
Next
Change Primary and Secondary Axis scale to fit as though the chart was separated. I change the primary axis scale from 0 to 1.6e7, and secondary axis scale from -7.0e7 to 7.0e7. At the same time, change display unit in millions, and remove all gridlines.
Dim ax As Microsoft.Office.Interop.PowerPoint.Axes
Dim axpri As Microsoft.Office.Interop.PowerPoint.Axis
Dim axsec As Microsoft.Office.Interop.PowerPoint.Axis
ax = c.Axes
axpri = ax.Item(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, _
Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlPrimary)
axsec = ax.Item(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, _
Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlSecondary)
axpri.MinimumScale = 0
axpri.MaximumScale = 1.6e7
axpri.DisplayUnit = Microsoft.Office.Interop.PowerPoint.XlDisplayUnit.xlMillions
axpri.HasMajorGridlines = False
axpri.HasMinorGridlines = False
axsec.MinimumScale = -7.0e7
axsec.MaximumScale = 7.0e7
axsec.DisplayUnit = Microsoft.Office.Interop.PowerPoint.XlDisplayUnit.xlMillions
axsec.HasMajorGridlines = False
axsec.HasMinorGridlines = False
Change Primary and Secondary Axis number format so that each axis only show its own intended value. Primary Axis more than 8M will not be shown, and Secondary Axis less than 30M will not be shown.
axpri.TickLabels.NumberFormat = "[<=8]0;;;"
axsec.TickLabels.NumberFormat = "[>=30]0;;;"
Recolor series in Secondary Axis to match series in Primary Axis.
Dim srPrev As Microsoft.Office.Interop.PowerPoint.Series = Nothing
For i = 4 To sc.Count
sr = sc.SeriesCollection(i)
srPrev = sc.SeriesCollection(i - 3)
sr.Format.Fill.ForeColor.RGB = srPrev.Format.Fill.ForeColor.RGB
Next
Delete Legend for Column4, Column5, and Column6 for a seamless Chart Legend.
c.Legend.LegendEntries(4).Delete()
c.Legend.LegendEntries(5).Delete()
c.Legend.LegendEntries(6).Delete()
[Optional] Add a neat color gradient for Data Points that exceed cut values.
Dim p As Microsoft.Office.Interop.PowerPoint.Point = Nothing
p = c.SeriesCollection("June").Points("Paris")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 270
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.8)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.97)
p = c.SeriesCollection("May").Points("Madrid")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 270
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.8)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.97)
p = c.SeriesCollection("Column5").Points("Paris")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 90
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.7)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.95)
p = c.SeriesCollection("Column4").Points("Madrid")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 90
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.7)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.95)
Voila! Hard work pays off, a broken y axis in PowerPoint chart.

Possible to highlight a textbox in SSRS with alternating colors?

I have a report in SSRS 2012 and it has alternating colors using an Expression for the Fill like so:
= IIf (RowNumber(Nothing) Mod 2 = 0, "WhiteSmoke", "White")
I want to highlight a field based on a value of a Field (in this case it's called R). I tried this:
= IIf (Fields!R.Value > 5, "Yellow" ,(IIf RowNumber(Nothing) Mod 2 = 0, "WhiteSmoke", "White"))
But I got an error when I preview the report.
The BackgroundColor expression for the text box 'R' contains an error: [BC30516] Overload resolutoin failed because no accessible 'IIf' accepts this number of arguments.
How can I implement what I want?
Try:
=IIf(Fields!R.Value > 5
, "Yellow"
, IIf(RowNumber(Nothing) Mod 2 = 0, "WhiteSmoke", "White"))

Resources