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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jdpadra
New Member

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
New Member

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors