Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Syndicate_Admin
Administrator
Administrator

Create column based on text-like data

Hello Community

I need to create a column based on an international encoding called ISIC that goes something like this:

CIIU

0990

1850

0114

3311

4560

I'm creating the column with the following code:

Actividad_Eco =
SWITCH(TRUE,
VR_PBI_COMERCIANTES[CIIU1]>=0111 && VR_PBI_COMERCIANTES[CIIU1]<=0322,"Agropecuario",
VR_PBI_COMERCIANTES[CIIU1]>=4511 && VR_PBI_COMERCIANTES[CIIU1]<=4799,"Comercio",
VR_PBI_COMERCIANTES[CIIU1]>=1011 && VR_PBI_COMERCIANTES[CIIU1]<=3320,"Industria",
VR_PBI_COMERCIANTES[CIIU1]>=3511 && VR_PBI_COMERCIANTES[CIIU1]<=3900,"Servicios",
VR_PBI_COMERCIANTES[CIIU1]>=5811 && VR_PBI_COMERCIANTES[CIIU1]<=9900,"Servicios",
VR_PBI_COMERCIANTES[CIIU1]>=0510 && VR_PBI_COMERCIANTES[CIIU1]<=0990,"Minas",
VR_PBI_COMERCIANTES[CIIU1]>=4911 & VR_PBI_COMERCIANTES[CIIU1]<=5320,"Transportation",
VR_PBI_COMERCIANTES[CIIU1]>=4111 && VR_PBI_COMERCIANTES[CIIU1]<=4390,"Construcción",
VR_PBI_COMERCIANTES[ISIC1]>=5511 && VR_PBI_COMERCIANTES[ISIC1]<=5630,"Hotels and Restaurants")

The column is throwing me the error of not being able to compare text-like values as integer values, but, as you can see in the example, there are codes that start with zero '0' and therefore I cannot transform the data to numbers. What do you recommend for this case?

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

VAR theCI = VALUE(VR_PBI_COMERCIANTES[CIIU1])

SWITCH(TRUE,
theCI >= 0111 && theCI <= 0322, "Agropecuario",
theCI >= 4511 && theCI <= 4799, "Comercio",
....y mas

View solution in original post

5 REPLIES 5
v-stephen-msft
Community Support
Community Support

Hi @juandroid ,

 

I think I understand what you mean, your error is that the CIIU column is in text format, so an error occurred when running the formula. You should use VALUE() to turn your text into numbers and then compare them.

 

Should be modified to

SWITCH(TRUE,
VALUE(VR_PBI_COMERCIANTES[CIIU1])>=0111 && VALUE(VR_PBI_COMERCIANTES[CIIU1])<=0322,"Agropecuario",...

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

HotChilli
Super User
Super User

VAR theCI = VALUE(VR_PBI_COMERCIANTES[CIIU1])

SWITCH(TRUE,
theCI >= 0111 && theCI <= 0322, "Agropecuario",
theCI >= 4511 && theCI <= 4799, "Comercio",
....y mas
HotChilli
Super User
Super User

Create a variable using VALUE(theField) and use that in the comparisons.   

It means less typing too.

The last line of the switch is using a different field. Correct?

I don't quite understand your answer, could you please explain a little more?

AlexisOlson
Super User
Super User

I think this should work if you change the "&" after 4911 to "&&".

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.