Datatable Add calculated column


#1

Hello,

I need some help on a quite simple subject.
I want to add a new calculated column to a datatable according to other string columns.
Simple example :
If(upper(colX) like “TOTO*” then “OK” else “KO”)
I found this, but it doesn’t work : IIF(UPPER([colX]) like “TOTO*”, “OK”, “KO”)

How to specify this calculation in the default argument ?
What type for Default argument (String ? Object ?) ?

Thanks


#2

try below

strCol is a variable

dataTable.Columns.Add(“NewCol”,GetType(string),“IIF([”+strCol+"] like ‘TOTO%’, ‘OK’, ‘KO’ )")


#3

Thanks for your help.
I’m using the activity “AddDataColumn” and I’ve tried in the following defaultValue argument :

  • “IIF(UPPER([col 1]) like ‘TOTO*’, ‘OK’, ‘KO’)”
  • “IIF(UPPER([”“col 1"”]) like ““TOTO*””, ““OK””, ““KO””)"
  • IIF(UPPER([col 1]) like “TOTO*”, “OK”, “KO”)
  • IIF(UPPER([“col 1”]) like “TOTO*”, “OK”, “KO”)
    But no one works.
    The first 2, it writes me the all string without calculated.
    The third, it doesn’t accept the like.
    The fourth, it doesn’t accept the “1” of “col 1”

An idea ?


#4

Well.
Impossible to use the UiPath activity, so I came back to the old “dataTable.Columns.Add” method.
And it’s working.
Just a last point, is there a way to use Upper or Ucase in the expression ?