Conditional row coloring in PowerBuilder 10.5 - colors

I'm using Power Builder 10.5 and I'm having a problem that seems simple at first, but can't get near the solution.
Is it possible to color rows differently depending on a condition? I have a select statement that retrieves numerous rows, that have different status: status A means the row is active, ERR that something is wrong, F that is finished, and so on...
What I need is the color of the column with status "ERR" to be red, and the color of the column with status "A" to be green. All else columns may be white.
I can do only half the job at the moment. I've added a dummy field in my Data Window, called "color". For all the cells I've written this in the design view, background color properties..
IF ( color =1, 65280, 16777215)
Now I move to the clicked event of my OK button where I retrieve data...
dw_1.Retrieve()
FOR ll_=1 to dw_1.RowCount()
ls_status=dw_1.GetItemString(ll_,"status")
IF ls_status='A' THEN
dw_1.SetItem(ll_, 'color', 1)
ELSEIF ls_status='ERR' THEN
??????
END IF
NEXT
The part with question marks is where I can't move forward. This highlights all my rows where status is "OK" green, but I can't seem to get the error ones red. I've tried manipulating the code in background color properties (trying to give him a condition if color=2), but I just keep getting the "Expression not valid" message.
Modify method also didn't help me much, as I can't seem to make him color only does rows with "ERR" status using Modify method.
Any advice will help.

You should set your 'color' column in the SQL statement itself.
SQL something like
CASE status WHEN 'ERR' THEN 'R' WHEN 'A' THEN 'G' END
Then in an expression on the background color of the columns of your datawindow you can put something like
if (color[0] = 'R', RGB(255,0,0), if (color[0] = 'G', RGB(0,255,0), RGB(0,0,0)))

In the datawindow properties of the object or band, go to the background tab. The Color property has a little button with an equal sign (=) on it. Click that and write an expression to derive a RGB value based on the value of a column.
I wrote an article about this stuff here: PBDJ Article

You can use case statements in the computed property. Something like this:
case( status when 'ERR' then RGB(255,0,0) when 'A' then RGB(0,255,0) else RGB(0,0,0) )

Related

How can i set a background color to a value in PowerBI using DAX?

I have made a formule in PowerBI using DAX. But i wanna set a background color to every value i have tried allot of things but i couldn't find anything. I My code is as following.
var Periods = SWITCH(TRUE(), Live <=maxdate, "Live", Accept <= maxdate, "Accept", Recieved < maxdate, "Recieved", Send < maxdate, "MessageSend",Decline < maxdate, "Request Declined")
For example i wanna add the color Red to Request declined. I wanna do this in my switch statement. How can i do this the best way ?
You would need a column or measure which defines the color based on your requirement / condition. This populate the color value based on the condition.
BGColor = VAR col = SELECTEDVALUE(Projects[Periods])
RETURN IF(col = "Request Declined", "#40E0D0", "#FFA07A")
Select the visual in which you would like to apply the formatting
Choose the field which needs the background color.
In the subsequent window, choose the Format by Field value, select the based on field
Select the newly created column/measure.
You could refer to this section to get a better picture.

(Excel 2013/Non-VBA) Format Data column based on value of another cell?

We have a column that is query driven, and the query partially formats the values in the column using math based off the value of a "user entry cell" on another sheet.
For the really curious, our query looks like this:
DECLARE #rotationsNum INT
SET #rotationsNum = ?
SELECT t.Piece_ID, t.Linear_Location, ((ROW_NUMBER() OVER(ORDER BY
Linear_Location) -1 )%#rotationsNum )*(360/#rotationsNum) AS Rotation FROM
(SELECT Position.Feature_Key, Piece_ID, ((Place-1)%(Places/#rotationsNum))+1 AS Linear_Location, Place, Measured_Value, Places FROM Fake.dbo.Position LEFT JOIN Fake.dbo.Features
ON Position.Feature_Key = Features.Feature_Key WHERE Position.Inspection_Key_FK = (SELECT Inspection_Key FROM Fake.dbo.Inspection WHERE Op_Key = ?)) AS t
ORDER BY Piece_ID, Linear_Location
The first parameter "#rotationsNum" is a cell that will always have a value between 1-4. IF the value is 1, the entire column will show "0"s, which we want to show as "N/A". However, it isn't as simple as "How to hide zero data.." Because if the "#rotationsNum" == 2, 3, or 4, there will still be 0 values in the column that need to be shown.
A "#rotationsNum" value of 2 will have the query write the column as such: example
So I am trying to come up with a way to format the column =IF(cell>1, do nothing, overwrite entire column to say "NA"). But I don't think it is that straight forward since the column is query driven.
My resolution was to format the column so that if the cell that drives the "#rotationsNum" parameter is below 2, then the whole column just gets "grayed out". It kind of makes it look like a redaction, and isn't as desirable as "NA", but it works for our purposes. Hopefully this solution helps someone else who stumbles upon this problem.

Excel Solver - Prevent Identically Named Results

This may sound a bit odd and maybe I'm just missing the forest through the trees on this question, but is there a way to force the Excel Solver to return only one instance of a result? As a short example imagine that we have some results on the likability of various objects (colors, animals, and shapes). We want the solver to return the three most preferred objects from this list.
Red (400)
Dog (120)
Circle (100)
Red (400)
Cat (90)
Square (75)
Blue (90)
Horse (60)
Triangle (70)
Green (80)
Snake (30)
Rectangle (40)
Yellow (40)
Rabbit (20)
Pentagon (15)
The problem is, of course, simplified in this example. Basically, my issue arises in that I want one of each type, namely Red, Dog, and Circle but I keep getting Red, Red (again), and Dog because the total is higher. I want to define a way to prevent Solver from returning two values named the same. I just can't seem to figure it out and Google doesn't seem to produce any viable responses either.
It's unclear how your data is setup, and this could affect how you setup the Solver problem, but here is one method (nb - this method will only work if you have 200 or fewer values to choose from).
Make Column A for "Category". This would have values such as "Color", "Animal", and "Shape".
Column B would be for "Type", and contain the information you provided. (e.g. Dog, Cat, ... Red, Blue, ... Circle, Square, ...)
Column C is the Value or Score for the type shown in Column B, again the information you provided.
Column D has fields that Solver will manipulate, let's call it "Selected". Selected will be a 0 or a 1.
Column E is the result of selection, a simple calculation, =C2*D2, filled down.
Make Cell H2 the sum of Column E. This will be your objective for Solver.
Make G3 through G5 the values in "Category" (Color, Animal, Shape).
Make H3 through H5 the total selected values in each category. That is =SUMIF($A$2:$A$16,"="&G3,$D$2:$D$16) filled down.
The workbook looks like this ...
... from this, you can setup Solver with the following ...
Set Objective: is $H$2
To: is set to Max. (i.e. you are looking for the most preferred)
By Changing Variable Cells: is set to $D$2:$D$16
Subject to the Constraints: has four entries. $D$2:$D$16 = binary; $H$3 = 1; $H$4 = 1; $H$5 = 1
Select a Solving Method: is set to Evolutionary. You can use GRG Nonlinear, but it takes longer.
The dialog looks like this ...
... with the following result, which meets your criteria ...

From a selected line in a chart, filter a table or pivot table

I am facing a challenge. In a chart with multiple lines, I would like to able when I click on a line or mouse over a line to see the corresponding datapoint in the the table or pivot table...So basically, filtering a table based on the element i click or select on a chart with my mouse.
Do you think that it is achievable ? What would be the methodology ? Is there a VBA code for this ? I have seen examples, but they are working on the oppiste way; click or mouse over an observation and the line is highlighted...
Thanks in advance
saskap
This is really complicated, you have to customize the code for each chart, this example code can be a starting point:
Dim p As Series
Dim pc As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ch As ChartObject: Set ch = Me.ChartObjects("Chart 1")
With ch
Dim s As Series: Set s = Nothing
On Error Resume Next: Set s = .Chart.SeriesCollection(Target.Value): On Error GoTo 0
If Not p Is Nothing And Not p Is s Then
p.Format.Fill.ForeColor.RGB = pc
End If
If Not s Is Nothing Then
Set p = s
pc = s.Format.Fill.ForeColor.RGB
With s
s.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End If
End With
End Sub
The first two rows are global variables that store which Series
object was highlighted last time and what was its original color,
this is needed to restore the original color when a different cell is
selected. Unfortunately global variables in VBA loose their value when the project is reset (e.g. the Stop button is pressed or an error occurs), so it is possible that this code colors a bar and then cannot color it back. If important, these information may be stored in invisible Cells or Chart data but that complicates the code.
The next line means that this is an event handler, a function that is called in response to a certain event, in this case when the selection changes on a certain worksheet (the one on which you insert this - you have to insert this into a worksheet module not a standard code module).
Next we look up the chart based on its name and assign it to a variable, which is of type ChartObject, so early binding will allows us to depend on the support of intellisense (if you type a . it shows members of interfaces).
Then we look up the Series inside the chart based on the name found in the newly selected cell's contents. Since we don't know if the new cell will have a valid name, we have to protect this line with disabling error handling and checking later if the s has a non-nothing value. - This part depends largly on the type of chart and how it represents data, it is possible that you will have to select data based on Series::XValues.
We check if there is a saved value for a previously highlighted bar and if it is different from the current selection, restore its original color.
Finally if the looking up the Series earlier was successful then s is non-null and we save the color of the current bar and highlight it with red fill.

SSRS pie chart color coding

I have an ssrs report where I have many pie charts with the fields pass and fail as well as up to 3 other miscellaneous fields and I wish to be able to color the pass always green and the fail always red but the other fields could be a default value. Is this even possible to do? I have seen code examples with code for custom color in pie charts but I have no clue how to do this and have not found where I would put my custom code. What im trying to do is slightly different from what all those other examples do whith only defining a few fields.
=Switch
(
Fields!ResultTypeDescription.Value = "Pass", "Green",
Fields!ResultTypeDescription.Value = "Fail", "Red",
Fields!ResultTypeDescription.Value = "Assigned To Machine", "Blue",
Fields!ResultTypeDescription.Value = "Not Yet Assigned", "Orange",
True , "Gray"
)
In order to get our dynamic coloring working,i overrode the colors from the palette. This is how it’s done. Right-click on the pie and select Series Properties. Select the Fill page and click the Expression (fx) button to define the color.

Resources