Forum Discussion
Interruptor
Hola
Me gustaría agregar una columna a una tabla existente en el modelo, pero el error es siguiente. ¿Alguna sugerencia por favor?:
La función 'SWITCH' no admite la comparación de valores de tipo Text con valores de tipo Integer. Considere la posibilidad de utilizar la función VALUE o FORMAT para convertir uno de los valores.
tenga en cuenta que [CalendarQuarterKey] es int y contiene valores como:
20153
20154
...
20201
...
StartMonthDayKey ?
SWITCH(
'myDate'[CalendarQuarterKey],
1, IZQUIERDA('myDate'[CalendarQuarterKey], 4) & "0105"),
2, IZQUIERDA('myDate'[CalendarQuarterKey], 4) & "0405"),
3, IZQUIERDA('Fecha'[CalendarQuarterKey], 4) & "0705"),
4, IZQUIERDA('myDate'[CalendarQuarterKey], 4) & "1005")
)
7 Replies
- az38Community Champion
Hola @arkiboys
probar CONVERT()
StartMonthDayKey = var _CalendarQuarterKey = LEFT(CONVERT('myDate'[CalendarQuarterKey], STRING), 4) RETURN SWITCH( 'myDate'[CalendarQuarterKey], 1, _CalendarQuarterKey & "0105"), 2, _CalendarQuarterKey & "0405"), 3, _CalendarQuarterKey & "0705"), 4, _CalendarQuarterKey & "1005") )- AnonymousNot applicable
, sigue recibiendo errores:
La sintaxis de ',' es incorrecta. (DAX(var _CalendarQuarterKey ? LEFT(CONVERT('Date'[Calendar Quarter Key], STRING), 4)RETURN SWITCH('Date'[CalendarQuarterKeyValue],1, _CalendarQuarterKey & "0105"),2, _CalendarQuarterKey & "0405"),3, _CalendarQuarterKey & "0705"),4, _CalendarQuarterKey & "1005")))).
- az38Community Champion
lo siento, paréntesis equivocados
StartMonthDayKey = var _CalendarQuarterKey = LEFT(CONVERT('myDate'[CalendarQuarterKey], STRING), 4) RETURN SWITCH( 'myDate'[CalendarQuarterKey], 1, _CalendarQuarterKey & "0105", 2, _CalendarQuarterKey & "0405", 3, _CalendarQuarterKey & "0705", 4, _CalendarQuarterKey & "1005" )
- tex628Community Champion
- danextianSuper User
Hola @arkiboys,
Las funciones de texto no funcionan en números. Para poder utilizar un número como texto tiene que convertirse primero en texto utilizando la función FORMAT. Por ejemplo:
Text to Number = FORMAT ( 'Table'[NumberField], "#" )En su caso, puede almacenar la versión de texto de myDate'[CalendarQuarterKey] en una variable y usarla en SWITCH en su lugar. También es necesario quitar el paréntesis de cierre adicional después de cada "01" ya que provocarán un error de sintaxis.
StartMonthDayKey = VAR TextToNumber = FORMAT ( 'myDate'[CalendarQuarterKey], "#" ) RETURN SWITCH ( 'myDate'[CalendarQuarterKey], 1, LEFT ( TextToNumber, 4 ) & "0105", 2, LEFT ( TextToNumber, 4 ) & "0405", 3, LEFT ( TextToNumber, 4 ) & "0705", 4, LEFT ( TextToNumber, 4 ) & "1005" )Además
- AnonymousNot applicable
- AnonymousNot applicable
Para el siguiente DAX, el error es:
La función 'SWITCH' no admite la comparación de valores de tipo Text con valores de tipo Integer. Considere la posibilidad de utilizar la función VALUE o FORMAT para convertir uno de los valores.StartQuarterYearMonthDayKey ?
Var TextToNumber (Var TextToNumber)
FORMAT ( izquierda('Fecha'[Clave del cuarto del calendario], 4), "-" )
devolución
SWITCH (
'Date'[CalendarQuarterKeyValue],
1, IZQUIERDA ( TextToNumber, 4 ) y "0105",
2, IZQUIERDA ( TextToNumber, 4 ) y "0405",
3, IZQUIERDA ( TextToNumber, 4 ) y "0705",
4, IZQUIERDA ( TextToNumber, 4 ) y "1005"
)