How to select columns using a wildcard search on column names in SPSS Modeler - spss-modeler

I am doing time series analyis predicting sales for a large amount of products. After executing the time series node, I get a table containing the original sales data and predicted values with a suffix "$TS-" before the product name. Now I would like to select / filter only those columns containing a "$TS-" in the column name.

There is no easy or straightforward way to do something like this. The simplest way, in my opinion, would be to
Add a 'Filter' node after the time series model nugget
Use the funnel button to "Remove all Fields"
Select to include each of the individual fields that you would like to keep
Make sure that the node is set to Include fields by default
If fields are added to your original data sources or if new fields are derived in the stream, you'll have to go back to this node and remove them, so it's not ideal.
The alternative is to use a stream script to change the inclusion and removal of the fields within a "Filter" node. The script below will search for a "Filter" node with the name given by the variable filterNodeName and search for fields with the prefix given by the variable fieldNamePrefix and keep only the fields that match the designated prefix.
filterNodeName = "TS Fields Only"
fieldNamePrefix = "$TS-"
diagram = modeler.script.diagram()
# Find the 'Filter' node
renameFieldsNode = diagram.findByType('filternode', filterNodeName)
# Get the input data model - the fields that go into the 'Filter' node
fields = renameFieldsNode.getInputDataModel()
# Loop through all of the fields
for field in fields:
fieldName = field.getColumnName()
if fieldName.startswith(fieldNamePrefix):
# If the field name starts with the designated prefix then include the field
renameFieldsNode.setKeyedPropertyValue('include', fieldName, True)
else:
# Otherwise do not include the field
renameFieldsNode.setKeyedPropertyValue('include', fieldName, False)

Related

Using MYSQLI to select rows in which part of a column matches part of an input

I have a database in which one of the columns contains a series of information 'tags' about the row that are stored as a comma-separated list (a string) of dynamic length. I am using mysqli within PHP, and I want to select rows in which any of these items match any of the items in an input string.
For example, there could be a row describing an apple, containing the tags: "tasty, red, fruit, sour, sweet, green." I want this to show up as a result in a query like: "SELECT * FROM table WHERE info tags IN ('blue', 'red', 'yellow')", because it has at least one item ("red") overlapping. Kind of like "array_intersect" in PHP.
I think I could use IN if each row had only one tag, and I could use LIKE if I used only one input tag, but both are of dynamic length. I know I can loop over all the input tags, but I was hoping to put this in a single query. Is that possible? If not, can I use a different structure to store the tags in the database to make this possible (something other than a comma separated string)?
I think the best would be to create tags table (id + label) then separate "table_tags" table which holds table_id and tag_id.
that means using JOINS to get the final result.
another (but lazy) solution would be to prefix and suffix tags with commas so the full column contains something like:
,tasty,red,fruit,sour,sweet,green,
and you can do a LIKE search without being worried about overlapping words (i.e red vs bored) and still get a proper match by using LIKE '%,WORD,%'

Including and Excluding Filter values based on a particular criteria

Attached is the mock data on which we are trying to do the following :
We have Configuration Id : which is a part of a car like dashboard of the car or tyres etc.
Then we have part attachments which tells you about the parts that make up an entire configuration. For eg : 'head lights', 'rear lights' and 'fog lamps' make up 'Lights'.
Problem Statement : We need to have 2 filters : Part attachment included and excluded such that, when part attachments included is selected as steering then I get 3 rows(marked in yellow in column E) based on selection. But in the part attachments excluded filter, we don't want the configuration id where the part attachment = 'Headlight'. This means that row no 17 should be eliminated when filtering gout headlamps from the filter.
So basically when part attachment excluded filter excludes 'headlight' then data in row no 17 should not be show in tableau.
I found this a little difficult to implement using normal filters in tableau.
Using normal filter you won't be able to achieve this, Try below method:
Create two parameters:
Include and exclude and take the respective database fields using the list radio button.
Now create 2 calcualted fields:
Include:
Parameter1 = Databasefield
Exclude:
Parameter2= database field
Now when placing the two parameters on to filters for include select True and for Exclude select False

Form Assembly :: Concatenate fields in a Repeatable section

I have a Type and Phone number field in FormAssembly which is repeatable. When users add 2 entries like the one below,
User Entries:
Type: "Mobile" Number:6787867890
Type: "Landline" Number:7898878987
I need to concatenate the above entries to a single field like the one below using Calculation Fields
Expected Result:
Mobile:6787867890|Landline:7898878987
Any idea on how this can be achieved using Calculation fields in FormAssembly?
Just got this working by using 2 Calculation Fields. In the Repeatable section, I added a Calculation field(vEntries) which is hidden. vEntries will concatenate Type: "Mobile" Number:6787867890 to "Mobile:6787867890".
I declare another Calculation field(vFinalEntry) outside the repeatable section, this field is responsible for concatenating all the vEntries.
So when the user enters the second entry Type: "Landline" Number:7898878987, the vFinalEntry variable will have the value "Mobile:6787867890|Landline:7898878987".

FileMaker - How to have distinct values listed on-screen?

I would like to have the distinct values of a repeating field listed in another field (in browse mode). The case is as follows:
I have a field that contains country names. The country names in this field may repeat themselves, thus when using the "List" function I get something like "France, France, France, Germany, Germany, Hungary".
How can I create a field that lists all the values from my country field, but has it grouped as "France, Germany, Hungary"?
In the case I could directly use a SQL query to interfere with the FileMaker databse I would use the GROUP BY statement.
To make a summary of all the values across every record, do as follows:
Make a new value list labeled 'Countries' (File Menu > Manage > Value Lists)
Make the value list 'Use Values From Field' and specify your repeating field
Create a new Calculation field, 'Listed Countries'
Set the calculation to type 'Text' and with the following code:
ValueListItems ( Get(FileName) ; "Countries" )
If you'd like to find the value for only the current record:
Make a new Table Occurrence, 'NewTO' of the same base table and link the two records by a unique index.
Change the 'Countries' value list so that it obtains values from 'NewTO' and your repeating field.
Select 'Only include related values starting from' and select your original Table Occurrence
If you'd like the list to update as the repeating field value changes, make certain that you Do Not Store Calculation Results for the field.

Create a new FileMaker layout showing unique records based on one field and a count for each

I have a table like this:
Application,Program,UsedObject
It can have data like this:
A,P1,ZZ
A,P1,BB
A,P2,CC
B,F1,KK
I'd like to create a layout to show:
Application,# of Programs
A,2
B,1
The point is to count the distinct programs.
For the life of me I can't make this work in FileMaker. I've created a summary field to count programs resetting after each group, but because it doesn't eliminate the duplicate programs I get:
A,3
B,1
Any help much appreciated.
Create a a summary field as:
cntApplicaiton = Count of Application
Do this by going into define fields, create a field called cntApplication, type summary. In the options dialogue make the summary field a count on application
Now create a new layout with a subsummary part and nobody. The subsummary should be sorted on Application. Put the Application and cntApplication fields in subsummary. If you enter browse mode and sort by Application you ought to get the data you want.
You can also create a calc field with the formula
GetSummary(cntApplication; Application)
This will allow you to use the total number of Applications with in a record
Since I also generate the data in this form, the solution I've adopted is to fill two tables in FileMaker. One provides the summary view, the other the detailed view.
I think that your problem is down to dupliate records and an inadequate key.
Create a text field called "App_Prog". In the options box set it to an auto-enter calc, unchecking the 'Do not replace...' option, and use the following calc:
Application & "_" & Program
Now create a self join to the table using App_Prog as the field on both sides, and call this 'MatchingApps'.
Now, create (if you don't alread have one) a unique serial number field, 'Counter' say, and make sure that you enter a value in each record. (Find all, click in the field, and use serial number option in'Replace Field Contents...')
Now add a new calc field - Is_Duplicate with the following calc...
If (Counter = MatchingApps::Counter; "Master Record" ; "Duplicate")
Finally, find all, click in the 'Application field, and use 'Replace Field Contents...' with a calculation to force the auto-enter calc for 'App_Prog' to come up with a value.
Where does this get you? You should now have a set of records that are marker either "Master Record" or "Duplicate". Do a find on "Master Record", and then you can perform your summary (by Application) to do a count of distinct application-program pairs.
If you have access to custom functions (you need FileMaker Pro Advanced), I'd do it like this:
Add the RemoveDuplicates function as found here (this is a recursive function that takes a list of strings and returns a list of unique values).
In the relationships graph, add another occurrence of your table and add an Application = Application relationship.
Create a calculated field in the table with the calculation looking something like this:
ValueCount(RemoveDuplicates(List(TABLE2::Program)))
You'll find that each record will contain the number of distinct programs for the given application. Showing a summary for each application should be relatively trivial from here.
I think the best way to do this is to create a separate applications table. So as you've given the data, it would have two records, one for A and one for B.
So, with the addition of an Applications table and your existing table, which I'll call Objects, create a relationship from Applications to Objects (with a table occurrence called ObjectsParent) based on the ApplicationName as the match field. Create a self join relationship between Objects and itself with both Application and Program as the match fields. I'll call one of the "table occurrences" ObjectsParent and the other ObjectsChildren. Make sure that there's a primary key field in Objects that is set to auto-enter a serial number or some other method to ensure uniqueness. I'll call this ID.
So your relationship graph has three table occurrences:
Applications::Applicaiton = ObjectsParent::Application
ObjectsParent::Application = ObjectsChildren::Application, ObjectsParent::Program = ObjectsChildren::Program
Now create a calculation field in Objects, and calculating from the context of ObjectsParent, give it the following formula:
AppCount = Count( ObjectsChildren::ID )
Create a calculation field in Applications and calculating from the context of the table occurrence you used to relate it to ObjectsParent with the following formula:
AppCount = ObjectsParent::AppCount
The count field in Objects will have the same value for every object with the same application, so it doesn't matter which one you get this data from.
If you now view the data in Applications in list view, you can place the Applications::Application and Applications::AppCount fields on the layout and you should get what you've requested.