- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Formula
Hello, I am looking to build a test column:
From the following script:
dt11 = current data table();
// Choisir colonnes commençant par employes
dur_cols = Filter Each( {col_name}, dt11 << Get Column Names( "String", Nominal ),
Starts With( col_name, "employes " )
);
// Nouvelle colonne
dt11 << New Column( "TEST EMPLOYES", Numeric, "Continuous", Format( "Best", 12 ) );
// Modifier la formule de colonne : TEST EMPLOYES
dt11:TEST EMPLOYES <<
Set Formula(
For( i = 1, i < n items(dur_cols), i++,
If(
(dur_cols[i] == dur_cols[i+1] | Is Missing( dur_cols[i+1] )),
:TEST EMPLOYES = 1
,
:TEST EMPLOYES = 0
)
)
);
The goal is to have 0s or 1s in the TEST EMPLOYES column depending on the conditions in the if loop... At the moment I can't create the test employees column with the values 0 or 1.
Thank you for your help
This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Formula
Doing the calculation from the original column is most likely easier
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(3),
Compress File When Saved(1),
New Column("Column",
Character,
"Nominal",
Set Values({"1-1-3", "2-2-2", "3-3", ""})
),
New Column("Column 1", Character, "Nominal", Set Values({"1", "2", "3", ""})),
New Column("Column 2", Character, "Nominal", Set Values({"1", "2", "3", ""})),
New Column("Column 3", Character, "Nominal", Set Values({"3", "2", "", ""}))
);
dt << New Column("R", Numeric, Nominal, Formula(
res = Associative Array(Words(:Column , "-")) << get keys;
Remove From(res, Contains(res, "")); // remove missing value
N Items(res) == 1;
));
Not sure how fully missing row should be taken into account, in this case it is treated as 0 but it can be changed to one modifying the final comparison
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Formula
What are the conditions when 1 or 0 should be added?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Formula
I start from an employee column, in which there are several fields filled in, such as "611 - 2000 - 300", there can be more than 3 fields filled in.
In my script I split this column from the "-" separator, so there are as many "employe..." columns as there are fields in the first "employe" column.
Condition TEST EMPLOYE = 1 :
All created employee columns are equal or missing value
Condition TEST EMPLOYE = 0 :
Different data in employee columns created (do not take into account when the column is empty)
Example 1:
employee column 1:300
employee column 2: 300
employee column 3: 500
TEST EMPLOYE = 0
Example 2:
employee column 1:300
employee column 2: 300
employee column 3:
TEST EMPLOYE = 1
This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Formula
Doing the calculation from the original column is most likely easier
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(3),
Compress File When Saved(1),
New Column("Column",
Character,
"Nominal",
Set Values({"1-1-3", "2-2-2", "3-3", ""})
),
New Column("Column 1", Character, "Nominal", Set Values({"1", "2", "3", ""})),
New Column("Column 2", Character, "Nominal", Set Values({"1", "2", "3", ""})),
New Column("Column 3", Character, "Nominal", Set Values({"3", "2", "", ""}))
);
dt << New Column("R", Numeric, Nominal, Formula(
res = Associative Array(Words(:Column , "-")) << get keys;
Remove From(res, Contains(res, "")); // remove missing value
N Items(res) == 1;
));
Not sure how fully missing row should be taken into account, in this case it is treated as 0 but it can be changed to one modifying the final comparison