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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
jdpadra
Regular Visitor

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 @jdpadra ,

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
jdpadra
Regular Visitor

Thanks!

v-yiruan-msft
Community Support
Community Support

Hi @jdpadra ,

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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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