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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
juandroid
Helper I
Helper I

Crear columna basado en datos tipo texto

Hola Comunidad

Necesito crear una columna basada en una codificación internacional llamada CIIU que va algo así:

CIIU

0990

1850

0114

3311

4560

 

La columna la estoy creando con el siguiente código:

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,"Transporte",
VR_PBI_COMERCIANTES[CIIU1]>=4111 && VR_PBI_COMERCIANTES[CIIU1]<=4390,"Construcción",
VR_PBI_COMERCIANTES[CIIU1]>=5511 && VR_PBI_COMERCIANTES[CIIU1]<=5630,"Hoteles y Restaurantes")

 

La columna me está botando el error de no poder comparar valores tipo texto como valores enteros, pero, como se puede ver en e ejemplo, hay códigos que empiezan con cero '0' y por lo tanto no puedo transformar los datos a números. Qué me recomiendan para este caso?

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

VAR theCI = VALOR(VR_PBI_COMERCIANTES[CIIU1])

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

View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

No @juandroid,

Creo que entiendo lo que quiere decir, su error es que la columna CIIU está en formato de texto, por lo que se produjo un error al ejecutar la fórmula. Debe usar VALUE() para convertir su texto en números y luego compararlos.

Debe modificarse a

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

Saludos

Esteban Tao

Si esta publicación ayuda,entonces considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.

Syndicate_Admin
Administrator
Administrator

VAR theCI = VALOR(VR_PBI_COMERCIANTES[CIIU1])

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

Cree una variable usando VALUE(theField) y utilí la use en las comparaciones.

También significa menos escritura.

La última línea del interruptor está usando un campo diferente. ¿Correcto?

No entiendo muy bien tu respuesta, podrías por favor explicarme un poco más?

Syndicate_Admin
Administrator
Administrator

Creo que esto debería funcionar si cambias el "&" después de 4911 a "&&".

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.