TIBCO Spotfire expressions : How to rename a group of nest columns into new names - spotfire

I have Bar chart with values colored by 2 different filters.
What I need is to rename each combination of the 2 filters into just one name.
i tried to write it with CASE expression but with no luck.
below screenshot, shows what is required.
Any ideas ?
Screenshot sample : Motor Type

Why did you case expression not work?
Something like that should work:
<CASE [COLUMN] WHEN "VALUE1" then "Category A" WHEN "VALUE2" then "Category B" ELSE "Category C" END>
But in your situation I would do
<if([column 2] in ('SALA','SUPP'),'Motor category A','Motor category B')>
Add this expression here (right click > custom expression) :

Related

Power Query excel

i am trying to use a if formula in power query. For example, if the Column contains “guy” then value is male and the false value is “female”. I tried different ways and I can’t find the right formula to use in power query. Can anyone help me please?
If you are entering this into the Add Custom Column dialog, something like (for case-insensitive):
= if Text.Contains([Column],"guy", Comparer.OrdinalIgnoreCase) then "male" else "female"
It sounds like you are wanting to conditionally replace values in a column, based on the existing values in that column? If so, you can use the Table.ReplaceValue function in Power Query:
= Table.ReplaceValue(Source,
each [Gender],
each if [Gender] = "guy" then "male" else "female",
Replacer.ReplaceText,{"Gender"})
That will change all values of "guy" to "male', and ALL other values to "female", as you stated.
You can also leave values in place that don't meet the criteria, by simply referencing the column name instead of a specifying a new value:
= Table.ReplaceValue(Source,
each [Gender],
each if [Gender] = "guy" then "male" else [Gender],
Replacer.ReplaceText,{"Gender"})
Create a table with a column called Gender, and load it to power query. Right-click on the column header and choose Replace Values to get the UI to build your statement for you, then replace the generated code with the above modification(s) and apply to your actual requirements. The key is using the each expression to tell Power Query to test at the row value level. If you omit each, you'll see the error:
"Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"
= Table.AddColumn(#"Changed Type","ColumnName",each if[Column] ="""Guy""" then"""Male""" else"""Female""")

Tabulator 5.2 New editor List option/value

In the new tabulator v5.2, the editor "select" was changed to "list", I have this code that was working fine in v5.1 but stop working in the new version, I hope someone can help me figured out what do I need to change to make it work again with this new version of tabulator.
Ex: in my table there are two columns with select dropdown values, the second column is dependent on the first. So if I select "Sales" in the first column, in the same row on the second column it will only show a list of "services" that belongs to the "Sales" department and so on.
In the code linked below you can see that in the first column when I click in a row in the "Dept" column, a list of values shows up, and if I select the value "Sales" it change to option "1".
{title:"DEPT", field:"dept", width:90, hozAlign:"left", editor:"list", editorParams:{values: {1:"Sales",2:"Service",3:"Bodyshop",4:"Carwash"}}},
{title:"WORK Type", field:"service", editor:"list", editorParams:{values: serviceList}},
jsfiddle
You can use the built-in lookup formatter to do that:
columns:[
{title:"DEPT", field:"dept",
width:90, hozAlign:"left",
editor:"list",
editorParams:{
values: {1:"Sales",2:"Service",3:"Bodyshop",4:"Carwash"}
},
formatter:"lookup",
formatterParams:{
1:"Sales", 2:"Service", 3:"Bodyshop", 4:"Carwash"
}},
Passing the same object of editorParams into the formatterParams would do your job.
Working Demo: https://jsfiddle.net/Mahesh1312/rzbxvym7/5/
Hope it helps!

How to select multiple rows based on header values?

I wish to iterate over rows of a Pandas dataframe while only checking for similarity within a few columns among the rows. Then, I want to check for a similarity condition, followed by a date comparison (which one is earlier/later) and apply corresponding changes to one element of the row selected.
For selecting particular rows, I kind of want something like this:
p=z["product_name", "Category 1", "Category 2", "Features"].iloc[i-1:i]
I know it's not correct, but it's just to give an idea. Select a row with only a few particular headers out of many.
i=1
while (i<=len(z)):
j=i+1
p=z["product_name", "Category 1", "Category 2", "Features"].iloc[i-1:i]
p=p.to_string(index=False)
while(j<=len(z)):
q=z["product_name", "Category 1", "Category 2", "Features"].iloc[j-1:j]
q=q.to_string(index=False)
if (p==q):
if(z["Update Date"].iloc[i-1:i]>z["Update Date"].iloc[j-1:j]):
z.drop(j, axis=0)
j=j+1
i=i+1
I know that most of this code is actually wrong but this is the approach I'm trying. Please suggest a better approach/function that solves this problem.
I don't know your question exactly, But there are Basic Issue in your code when you start i-1:i, it gives only one value why you use this line instead of directly one variable
p=z["product_name", "Category 1", "Category 2", "Features"].iloc[i-1:i]
try This:
p=z[["product_name", "Category 1", "Category 2", "Features"]].iloc[i-1:i]

"Does Not Contain" text filter filters too much

By using Power Query, I have created an address list from address fields in approx. 15000 individual excel files.
I now have a list with 15143 rows but I have run into problems with the "Does Not Contain" Text filter.
I want to keep rows that do not contain the search term "foo" in a specific column.
When I first use the "Contains" "foo" Text Filter it returns a list of 150 rows
But when I use the "Does Not Contain" "foo" Text Filter instead the list is shortened to only 3218 rows.
A bit unexpected result...
If I recall my maths lessons correctly 15143-150=14993, not 3218.
This is driving me nuts!
Do I do something wrong or is it the Almighty Microsoft Bug that has hit me, once again?
This behavior is related to the expected Sql logic for null: if a row field is null, it doesn't contain "foo" but it also doesn't not contain "foo". Put differently, a WHERE filter skips rows that evaluate to null, and not null is also null.
You can see this in Power Query:
let
Source = Table.FromColumns({{null, "foo", "bar"}}),
FilteredRows = Table.SelectRows(Source, each
not Text.Contains([Column1], "foo") or Text.Contains([Column1], "foo"))
in
FilteredRows
... only returns the last two rows.
In Power Query if you want to avoid this bizarre kind of logic, you can replace null with empty string and then you get nicer behavior:
= Table.ReplaceValue(Source,null,"",Replacer.ReplaceValue,{"Column1"})

spotfire- showing column based on conditions

I have two visualization below. Is there anyway to combine those two together and show user_name and service_id based another column "Type".
For examples if [type]="user", this table will show "requestor name" and "user name". if [type]="service" then this same table will show "requestor name" and "service id"
Thanks
There are at least 3 ways you can approach this.
You can create a calculated column using one of the expressions below and use this column in your visualization.
Option 1
case
when [user_name] is null or [user_name] = "" then [service id]
else [user_name]
end
Option 2
If(([user_name] is null) or ([user_name]=""),[service id],[user_name])
Option 3
You can use one of the expressions above in the category axis of your expression.

Resources