Power table text display of binary value and dynamic display in either first or second column

Does anybody know how to:

  1. display a value in the column in the power table as text1 when the value is 1 and text 2 when the value is 0 in the database table connected to the power table?
    2 how to display a value in either column 1 or column 2 based on the value from column 3


You could do the logic in the query but this is probably not desirable or best practice.

I was originally going to suggest a script transform but realised these are not used in Vision :sweat_smile:

Alternatively, you could create an event script that calls system.db… which you can then return a dataset to iterate over. In the loop you can apply the logic you desire and then pass the resulting dataset to the power table.

1 Like

Implement the logic in the power table’s configureCell extension function. For question 1, something like this:

    if colName=='someColumn':
        return {'text': 'text 1' if value else 'text 2'}
    return None

For q2, you can use the self.data and rowIndex to look up values in other columns to use while deciding how to display the column at hand.


thank you both for great help
Question 1 sorted the only issue i have the column keeps displaying tickboxes ticked or not depending on the value from the database. Any idea how to display just text and get rid of the tickbox? pls see the screenshot of the tickbox

Ah, didn’t think your data was boolean, and didn’t realize the text would show up that way. ):

You’ll have to use a custom renderer. A simple Swing Label might do:

    if colName=='someColumn':
        from javax.swing import JLabel
        c = JLabel('text 1' if value else 'text 2')
        c.font = self.font
        return {'renderer': c}
    return None

That might need to be tweaked if you need other appearance properties.

I believe extension function might be bad for performance on big table. Can i use somehow SQL conditions eg. step 1 create a view which includes SELECT with many conditions then Step2 query the view and based on the value from Column A i will but the value from Column B either into Column C or D inside power table.
Any idea what SQL IF statement would look like? Does the driver supports this sort of queries at all?

@hewking32, it should be possible. However, my only concern is that you will just be shifting the performance degradation to your SQL server (I am not experienced enough with SQL optimisations to say by how much, it could be negligible). @pturmel or others might be better placed to comment.

What SQL are you using (assuming MSSQL)?