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
Jmrc16
Frequent Visitor

Sales LY till same period

Hello 

I have a report with the measure: 

CALCULATE(
        [Vendas],
       SAMEPERIODLASTYEAR('Date Table'[Date]), 'Date Table'[Month Number]<=MONTH(MAX(SaleTransactionDetails[CreateDate]))

It gives me the LY sales till the same month of the maximum sales dates. However, how can I do it if I want to calculate the LY sales till the same last year date? 
For example, if I have sales between 01/01/2025 and 03/09/2025, sales LY sould sum the lst year sales between 01/01/2024 and 03/09/2024.
2 ACCEPTED SOLUTIONS
FBergamaschi
Solution Sage
Solution Sage

I would suggest to

 

1 - create a calculated column in the Calendar table

 

Past present Future =
VAR _MaxSalesDate = MAX ( Sales[Date] )
RETURN
IF (
     'Calendar'[Date] < _MaxSalesDate,
     "Past",
     IF (
        'Calendar'[Date] = _MaxSalesDate,
        "Present",
        "Future"
     )
)

 

2 - use this DAX template code for the measure

 

Sales LY up to Max Date Current Year =
CALCULATE(
    [Sales],
    CALCULATETABLE(
        SAMEPERIODLASTYEAR('Calendar'[Date]),
        'Calendar'[Past present Future] <> "Future"
    )
)
 
In this way you have a very fast DAX and a simple implementation
 
The result is here (Sales started i n2023 and in 2023 are up to dicember - full year - , but you see only up to july as in 2024 since last Sale date is in july 2004, this is your case)
 
FBergamaschi_0-1756921674554.png

 

If you want to see details, file is here for your convenience

 

https://drive.google.com/drive/folders/1syEbfXegdWm_ZT7kW4SsMXFvWjgLj0gz?usp=drive_link

 

 

If this helped, please consider giving kudos and mark as a solution

@mein replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

Please try something like below whether it works.

And, for your reference, please check the attached pbix file.

 

 

Last Year expected result: = 
	VAR _maxdate = MAX(SalesTransactionDetails[CreateDate])
	VAR _untilmaxdate = ADDCOLUMNS(
		FILTER(
			'Date Table',
			'Date Table'[Date] <= _maxdate
		),
		"@lastyearsales", CALCULATE(
			[Vendas],
			SAMEPERIODLASTYEAR('Date Table'[Date])
		)
	)
	RETURN
		SUMX(
			_untilmaxdate,
			[@lastyearsales]
		)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

6 REPLIES 6
v-tejrama
Community Support
Community Support

Hi  @Jmrc16 ,

 

Thank you @Jihwan_Kim  and  @FBergamaschi  for the response provided! 

Has your issue been resolved? If the response provided by the community member addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

 

Thank you for your understanding!

Hi @v-tejrama ,

Yes, I have already marked the solution.

thank you all

Jihwan_Kim
Super User
Super User

Hi,

Please try something like below whether it works.

And, for your reference, please check the attached pbix file.

 

 

Last Year expected result: = 
	VAR _maxdate = MAX(SalesTransactionDetails[CreateDate])
	VAR _untilmaxdate = ADDCOLUMNS(
		FILTER(
			'Date Table',
			'Date Table'[Date] <= _maxdate
		),
		"@lastyearsales", CALCULATE(
			[Vendas],
			SAMEPERIODLASTYEAR('Date Table'[Date])
		)
	)
	RETURN
		SUMX(
			_untilmaxdate,
			[@lastyearsales]
		)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
FBergamaschi
Solution Sage
Solution Sage

I would suggest to

 

1 - create a calculated column in the Calendar table

 

Past present Future =
VAR _MaxSalesDate = MAX ( Sales[Date] )
RETURN
IF (
     'Calendar'[Date] < _MaxSalesDate,
     "Past",
     IF (
        'Calendar'[Date] = _MaxSalesDate,
        "Present",
        "Future"
     )
)

 

2 - use this DAX template code for the measure

 

Sales LY up to Max Date Current Year =
CALCULATE(
    [Sales],
    CALCULATETABLE(
        SAMEPERIODLASTYEAR('Calendar'[Date]),
        'Calendar'[Past present Future] <> "Future"
    )
)
 
In this way you have a very fast DAX and a simple implementation
 
The result is here (Sales started i n2023 and in 2023 are up to dicember - full year - , but you see only up to july as in 2024 since last Sale date is in july 2004, this is your case)
 
FBergamaschi_0-1756921674554.png

 

If you want to see details, file is here for your convenience

 

https://drive.google.com/drive/folders/1syEbfXegdWm_ZT7kW4SsMXFvWjgLj0gz?usp=drive_link

 

 

If this helped, please consider giving kudos and mark as a solution

@mein replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

johnt75
Super User
Super User

You could use

Sales LY =
VAR MaxDate =
    CALCULATE (
        MAX ( SaleTransactionDetails[CreateDate] ),
        REMOVEFILTERS ( 'Date Table' )
    )
VAR DatesThisYear =
    DATESBETWEEN ( 'Date Table'[Date], DATE ( YEAR ( MaxDate ), 1, 1 ), MaxDate )
VAR Result =
    CALCULATE ( [Vendas], SAMEPERIODLASTYEAR ( DatesThisYear ) )
RETURN
    Result

I tried this solution, but when I put the measure in a matrix and put month in the lines, value doesn´t filter, it only shows the same value for al months. I think it's the "removefiltrs" impact

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.