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
Anonymous
Not applicable

Error con función Switch

Estoy teniendo problemas con la función switch

Necesito agregar una columna con fórmula y que haga:
Si en la columna "semana" dice "Semana 1" y en la columna "mes" dice 4, entonces en la columna nueva agregar "14"
Si en la columna "semana" dice "Semana 2" y en la columna "mes" dice 4, entonces en la columna nueva agregar "15"
Si en la columna "semana" dice "Semana 3" y en la columna "mes" dice 4, entonces en la columna nueva agregar "16"
Si en la columna "semana" dice "Semana 4" y en la columna "mes" dice 4, entonces en la columna nueva agregar "17"
Si en la columna "semana" dice "Semana 5" y en la columna "mes" dice 4, entonces en la columna nueva agregar "18"
Si en la columna "semana" dice "Semana 1" y en la columna "mes" dice 5, entonces en la columna nueva agregar "18"
Si en la columna "semana" dice "Semana 2" y en la columna "mes" dice 5, entonces en la columna nueva agregar "19" 

Y así sucesivamente.
El código que tengo es

SWITCH (
True ()

    'Tabla'[Atributo] = "Semana 1" && 'Tabla'[mes] = 4, 14,

    'Tabla'[Atributo] = "Semana 2" && 'Tabla'[mes] = 4, 15,

    'Tabla'[Atributo] = "Semana 3" && 'Tabla'[mes] = 4, 16,

    'Tabla'[Atributo] = "Semana 4" && 'Tabla'[mes] = 4, 17,

    'Tabla'[Atributo] = "Semana 5" && 'Tabla'[mes] = 4, 18,

    'Tabla'[Atributo] = "Semana 1" && 'Tabla'[mes] = 5, 18,

    'Tabla'[Atributo] = "Semana 2" && 'Tabla'[mes] = 5, 19,

    'Tabla'[Atributo] = "Semana 3" && 'Tabla'[mes] = 5, 20,

    'Tabla'[Atributo] = "Semana 4" && 'Tabla'[mes] = 5, 21,

    'Tabla'[Atributo] = "Semana 5" && 'Tabla'[mes] = 5, 22,

    'Tabla'[Atributo] = "Semana 1" && 'Tabla'[mes] = 6, 23,

    'Tabla'[Atributo] = "Semana 2" && 'Tabla'[mes] = 6, 24,

    'Tabla'[Atributo] = "Semana 3" && 'Tabla'[mes] = 6, 25,

    'Tabla'[Atributo] = "Semana 4" && 'Tabla'[mes] = 6, 26,

    'Tabla'[Atributo] = "Semana 1" && 'Tabla'[mes] = 7, 27,

    'Tabla'[Atributo] = "Semana 2" && 'Tabla'[mes] = 7, 28,

    'Tabla'[Atributo] = "Semana 3" && 'Tabla'[mes] = 7, 29,

    'Tabla'[Atributo] = "Semana 4" && 'Tabla'[mes] = 7, 29,

    'Tabla'[Atributo] = "Semana 5" && 'Tabla'[mes] = 7, 30,

    'Tabla'[Atributo] = "Semana 1" && 'Tabla'[mes] = 8, 30,

    'Tabla'[Atributo] = "Semana 2" && 'Tabla'[mes] = 8, 31,

    'Tabla'[Atributo] = "Semana 3" && 'Tabla'[mes] = 8, 32,

    'Tabla'[Atributo] = "Semana 3" && 'Tabla'[mes] = 8, 33,

    'Tabla'[Atributo] = "Semana 4" && 'Tabla'[mes] = 8, 34,

    BLANK ()

)

Gracias por el apoyo

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create two calculated columns as below to get the expected result:

Column = 
SWITCH (
    TRUE (),
    'Tabla'[mes] = 4,
        14 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1,
    'Tabla'[mes] = 5,
        18 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1,
    'Tabla'[mes] = 6,
        23 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1,
    'Tabla'[mes] = 8,
        30 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1
)
Weeknum = 
IF (
    ISBLANK ( Tabla[Column] ),
    IF (
        'Tabla'[Atributo] = "Semana 4",
        29,
        IF (
            'Tabla'[Atributo] = "Semana 5",
            30,
            27 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1
        )
    ),
    [Column]
)

vyiruanmsft_0-1712897966551.png

Best Regards

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks!

v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create two calculated columns as below to get the expected result:

Column = 
SWITCH (
    TRUE (),
    'Tabla'[mes] = 4,
        14 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1,
    'Tabla'[mes] = 5,
        18 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1,
    'Tabla'[mes] = 6,
        23 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1,
    'Tabla'[mes] = 8,
        30 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1
)
Weeknum = 
IF (
    ISBLANK ( Tabla[Column] ),
    IF (
        'Tabla'[Atributo] = "Semana 4",
        29,
        IF (
            'Tabla'[Atributo] = "Semana 5",
            30,
            27 + VALUE ( RIGHT ( 'Tabla'[Atributo], 1 ) ) - 1
        )
    ),
    [Column]
)

vyiruanmsft_0-1712897966551.png

Best Regards

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

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.