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

problema con mes pasado

¡Hola Comunidad! Tengo un problema a la hora de ver el mes anterior, la idea de este código es que si estoy en enero que muestre la temporada de diciembre del año pasado. Intenté ocupando previous month o dateadd, sin embargo, no logré armar la formula. Actualmente este es la que estoy ocupando, pero tampoco funciona. ¡Agradecería su ayuda, Saludos!

IF (

    YEAR( Calendario[Date] ) = year(date(2023,01,15))

    && month (Calendario[Date] ) = month(date(2023,01,15))-1,

    1, if(

YEAR( Calendario[Date] ) = year(date(2023,01,15))-1

    && month (Calendario[Date] ) = month(date(2023,01,15))-(month(date(2023,01,15))-1),1,0)

)

(la fecha debería ser today(), pero estaba probando suponiendo que el mes fuera enero)

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

HI @Aileen167,

I think it should relate to you extract the month number and minus it with 1. These conditions are equal to filter records who equal to current year and zero-month number. (this is an invalid date value)
I'd like to suggest you directly move month transform calculations into the date function:

formula =
VAR _cDate =
    DATE ( 2023, 01, 15 )
VAR _pDate =
    DATE ( YEAR ( _cDate ), MONTH ( _cDate ) - 1, DAY ( _cDate ) )
RETURN
    IF (
        YEAR ( Calendario[Date] ) = YEAR ( _cDate )
            && MONTH ( Calendario[Date] ) = 1,
        _pDate,
        _cDate
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Aileen167,

I think it should relate to you extract the month number and minus it with 1. These conditions are equal to filter records who equal to current year and zero-month number. (this is an invalid date value)
I'd like to suggest you directly move month transform calculations into the date function:

formula =
VAR _cDate =
    DATE ( 2023, 01, 15 )
VAR _pDate =
    DATE ( YEAR ( _cDate ), MONTH ( _cDate ) - 1, DAY ( _cDate ) )
RETURN
    IF (
        YEAR ( Calendario[Date] ) = YEAR ( _cDate )
            && MONTH ( Calendario[Date] ) = 1,
        _pDate,
        _cDate
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Muchas gracias! ahora que esta en date() retorna un 12

 

 

flag =

Var c_fecha= date(year (today()), Month (today())-1, Day(today()))
Return
IF (
YEAR( Calendario[Date] ) = year(today())
&& month (Calendario[Date] ) =Month( c_fecha),
1, 0
)

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.