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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Diego_Vialle
Helper II
Helper II

DAX - Calculate same period of previous year

I have the following formula below in DAX, to calculate customers who NEVER PURCHASED BUT PURCHASED in the last two months. How do I use SAMEPERIODLASTYEAR for her?

 

Novos Clientes Bimestrais =
VAR AllOldCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS,
SBOPRODMS[Data NF]
< TODAY () - 60,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
VAR AllNewCustomers =
CALCULATETABLE (
VALUES ( SBOPRODMS[Nome do PN] ),
SBOPRODMS[Data NF]
< TODAY () ,
SBOPRODMS[Documento] = "Nota fiscal de saída"
)
RETURN
IF(ISBLANK((COUNTROWS ( EXCEPT (AllNewCustomers, AllOldCustomers )))),0,COUNTROWS ( EXCEPT (AllNewCustomers, AllOldCustomers )))
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@Diego_Vialle 

Please try

Novos Clientes Bimestrais PY =
VAR PreviousYearDate =
    DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Nome do PN] ),
        SBOPRODMS,
        SBOPRODMS[Data NF] < PreviousYearDate - 60,
        SBOPRODMS[Documento] = "Nota fiscal de saída"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Nome do PN] ),
        SBOPRODMS[Data NF] < PreviousYearDate,
        SBOPRODMS[Documento] = "Nota fiscal de saída"
    )
RETURN
    IF (
        ISBLANK ( ( COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) ) ) ),
        0,
        COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )
    )

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

@Diego_Vialle 

Please try

Novos Clientes Bimestrais PY =
VAR PreviousYearDate =
    DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
VAR AllOldCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Nome do PN] ),
        SBOPRODMS,
        SBOPRODMS[Data NF] < PreviousYearDate - 60,
        SBOPRODMS[Documento] = "Nota fiscal de saída"
    )
VAR AllNewCustomers =
    CALCULATETABLE (
        VALUES ( SBOPRODMS[Nome do PN] ),
        SBOPRODMS[Data NF] < PreviousYearDate,
        SBOPRODMS[Documento] = "Nota fiscal de saída"
    )
RETURN
    IF (
        ISBLANK ( ( COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) ) ) ),
        0,
        COUNTROWS ( EXCEPT ( AllNewCustomers, AllOldCustomers ) )
    )
Whitewater100
Solution Sage
Solution Sage

Hello:

Once you have you measure for this year, I'll name it Measure A then 

SPLY = CALCULATE([Measure A], SAMEPERIODLASTYEAR([Dates, Date]))

 

Dates[Date] is the date field from your date table. It is critical to have date table, marked as date table and connected to your fact table with one to many relationship. Then the time intel functions work as expected.

 

I hope this helps!

I used it as directed and got the same result as the current period:

 

Novos Clientes Bimestrais LY = CALCULATE([Novos Clientes Bimestrais],SAMEPERIODLASTYEAR(dCalendario[Date].[Date]))
 
 

Hi Diego:

 

I will attah a file. Please look at inventory measure and Inv SPLY. This should help explain. The Date Table plays a big role in this.

https://drive.google.com/file/d/14G9U23xIV9_f57l2M7ChY-KWPif8M3Dp/view?usp=sharing 

 

Inv Total = SUM(Data[Invoice Amount])
Inv Total SPLY = CALCULATE([Inv Total], SAMEPERIODLASTYEAR(Dates[Date]))
 
I hope this helps!

Hi Diego

try delete ".[Date]" part. If not working try by adding REMOVEFILTERS ( dCalendario )

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.