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
cecitorresHF
Helper I
Helper I

End of the Month Previous Year

Hola 

 

Tengo una tabla de ventas que se actualiza diario, esta tabla contiene la venta actual (dia a dia), venta año pasado (usando la funcion SAMEPERIOD) y necesito una medida mas que me indique la venta total al final del mes pero del año anterior.

Alguna sugerencia para esta medida?

1 ACCEPTED SOLUTION

Hi @cecitorresHF ,

 

I find that there are no Date column in your Matrix visual. Therefore I guess you have a date slicer to select one month. Right?

cecitorresHF_2-1626919518538.png

 

If my guess is correct, try to change the measure like so:

Sales of Last Year Month = 
VAR ThisYear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
VAR ThisMonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR LastYearMonthStart =
    DATE ( ThisYear - 1, ThisMonth, 1 )
VAR LastYearMonthEnd =
    EOMONTH ( LastYearMonthStart, 0 )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Sales] ),
        FILTER (
            ALLEXCEPT('Sales',Sales[Branch] ),             ----------use ALLEXCEPT
            'Sales'[Date] >= LastYearMonthStart
                && 'Sales'[Date] <= LastYearMonthEnd
        )
    )

 

Or this:

Sales of Last Year Month =
VAR ThisYear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
VAR ThisMonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR LastYearMonthStart =
    DATE ( ThisYear - 1, ThisMonth, 1 )
VAR LastYearMonthEnd =
    EOMONTH ( LastYearMonthStart, 0 )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Sales] ),
        FILTER (
            ALL ( 'Sales' ),
            'Sales'[Branch] = MAX ( Sales[Branch] )
                && 'Sales'[Date] >= LastYearMonthStart
                && 'Sales'[Date] <= LastYearMonthEnd
        )
    )

 

 

Best Regards,

Icey

 

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

10 REPLIES 10
Icey
Community Support
Community Support

Hi @cecitorresHF ,

 

How about this:

Sales of Last Year Month = 
VAR ThisYear =
    YEAR ( MAX ( 'Table'[Date] ) )
VAR ThisMonth =
    MONTH ( MAX ( 'Table'[Date] ) )
VAR LastYearMonthStart =
    DATE ( ThisYear - 1, ThisMonth, 1 )
VAR LastYearMonthEnd =
    EOMONTH ( LastYearMonthStart, 0 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Date] >= LastYearMonthStart
                && 'Table'[Date] <= LastYearMonthEnd
        )
    )

lastyearmonth.PNG

 

 

Best Regards,

Icey

 

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

Hola 

Esta vez no me da ningun valor.

aqui te pongo un  screenshot de mis tablas 

cecitorresHF_0-1626916247065.png

 

cecitorresHF_1-1626916261009.png

 

Hi @cecitorresHF ,

 

Please modify your measure like so:

 

cecitorresHF_0-1626916247065.png

 

 

Best Regards,

Icey

 

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

Aun no me muestra ningun valor.

cecitorresHF_1-1626919493073.png

 

 

cecitorresHF_2-1626919518538.png

 

 

 

 

Hi @cecitorresHF ,

 

What is your data model? Is there a special part? Could you create a sample .pbix or just some sample data for me to test? No need for real data, just want to understand your scenario more clearly.

 

Reference: How to provide sample data in the Power BI Forum - Microsoft Power BI Community

 

 

Best Regards,

Icey

Tengo dos tablas, no estoy segura como pasarte un link aqui pero te explico como son.

 

Calendara table:

Contiene una columna con un listado de fechas 

cecitorresHF_0-1626922339942.png

Sales Table 

Contiene tres columnas, Branch, Date, Total

cecitorresHF_1-1626922453792.png

 

Ambas tablas estan relacionadas en base a la fecha. Calendar table [Date] ----> Sales Table [Date]

 

Hi @cecitorresHF ,

 

I find that there are no Date column in your Matrix visual. Therefore I guess you have a date slicer to select one month. Right?

cecitorresHF_2-1626919518538.png

 

If my guess is correct, try to change the measure like so:

Sales of Last Year Month = 
VAR ThisYear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
VAR ThisMonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR LastYearMonthStart =
    DATE ( ThisYear - 1, ThisMonth, 1 )
VAR LastYearMonthEnd =
    EOMONTH ( LastYearMonthStart, 0 )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Sales] ),
        FILTER (
            ALLEXCEPT('Sales',Sales[Branch] ),             ----------use ALLEXCEPT
            'Sales'[Date] >= LastYearMonthStart
                && 'Sales'[Date] <= LastYearMonthEnd
        )
    )

 

Or this:

Sales of Last Year Month =
VAR ThisYear =
    YEAR ( MAX ( 'Calendar'[Date] ) )
VAR ThisMonth =
    MONTH ( MAX ( 'Calendar'[Date] ) )
VAR LastYearMonthStart =
    DATE ( ThisYear - 1, ThisMonth, 1 )
VAR LastYearMonthEnd =
    EOMONTH ( LastYearMonthStart, 0 )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Sales] ),
        FILTER (
            ALL ( 'Sales' ),
            'Sales'[Branch] = MAX ( Sales[Branch] )
                && 'Sales'[Date] >= LastYearMonthStart
                && 'Sales'[Date] <= LastYearMonthEnd
        )
    )

 

 

Best Regards,

Icey

 

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

Icey
Community Support
Community Support

Hi @cecitorresHF ,

 

Does this work?

 

 

Best Regards,

Icey

amitchandak
Super User
Super User

@cecitorresHF , if current month July, then the last Dec is 7/8 months awa. depending on formula we use 

 

last year last month = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1*(month(Today())+1) ,MONTH)))

 

 

Measure = var _max = maxx(ALLSELECTED('Date'), 'Date'[FY Month]) +1 // remove +1 if needed
return
CALCULATE([Sales],DATESMTD(DATEADD('Date'[Date],-1*_max,MONTH)))

 

 

or

 

last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth(dateadd('Date'[Date],-1*month(Today()),MONTH)))

 

Hola 

 

Utilice la formula que me proporcionaste pero me calcula la venta total de un mes diferente, en este momento estoy intentando calcular las ventas de julio 2021(actual), mismo periodo año pasado y total julio 2020, sin embargo la formula me calcula el total para noviembre 2020 

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.