Link to home
Start Free TrialLog in
Avatar of nathanpz
nathanpz

asked on

Dataset Column Expression With Conditional Outputs

Hi,

How do you set a column expression to assign a large number of string values that are determined by an existing column value?

I have numbers ranging from 0 to 30 say in my existing [New Score] column. I wan't my column expression on my [Level] column to show the following:

New Score                 Level

1-3                              A
3-6                              B
6-9                              C
etc                              etc
24-27                           I
27-30                           J

I have used an IIF statement before to handle just two classifications "High" and "Low" levels, but cannot get VB.NET to extend to the multiple-argument. The line below works fine for two [Level] values only.

ds.Tables(2).Columns("Level").Expression = "IIF([New Score] < 15, 'Low', 'High')"

How do I get more than a true/false conditional expression?

Thanks,
Nathan.
Avatar of RonaldBiemans
RonaldBiemans

Well you could nest your iif, like

Dim s As Integer = 12
       ds.Tables(2).Columns("Level").Expression = "IIF([New Score] < 4, "A",IIF([New Score] < 7,"B", IIF([New Score] < 10,"C", etc... )"
or you could use the switch function, something like

dim s as integer = 9
MsgBox(Microsoft.VisualBasic.Switch(s < 4, "A", s < 6, "B", s < 10, "C"))
Avatar of nathanpz

ASKER

Hi RonaldBiemans,

I don't think the IIF statement can be nested in VB.NET. It says I am using too many arguments if I have more than IIF(argument,val_true,val_false).

Also, the Switch function wont allow me to use the [New Score] column values. I can't easily code the switch function to alter each [Level] column entry because the [Level] column is readonly and part of a dataset so it needs to use the Dataset.DataColumn.Expression command. Do you know how this could be coded?

Any ideas how to alter on of the above functions to work with my dataset column?

Thanks,
Nathan.

I'll have a look, but I'm pretty sure the iif can be nested.
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could you post your expression maybe you made a small type error.
Thanks for persevering RonaldBiemans,

I wasn't being careful enough with the number of arguments in the nested IIF statement.

The points are yours.

Thanks again.
Nathan.