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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ajve22
Frequent Visitor

Previous Year Sales

Hi,

I am trying to calculate last year sales using minimum line of dax code as below:

 

Sales Last Year = CALCULATE( [Sales] , PREVIOUSYEAR('Date (Sales Order)'[Order Date] ) )
 
It gives correct value when use this on matrix visual along with the year and month on rows but gives blank when using it on the card visual.
So, I need to show the previous year sales on matrix visual using year and motnhs on rows which can diplay previous year sales for all the years and on the card viusal it should show just the last year sales.  
Please suggest how to achieve this using minimun lines of dax code, so it can show value on card visual also.
 
Thanks 
5 REPLIES 5
Arul
Super User
Super User

@ajve22 ,

try this as a measure,

Last Year Sales = 
VAR _result = CALCULATE(
    [Sales],
    FILTER(Date (Sales Order),YEAR(Date (Sales Order)) = YEAR(MAX(Date (Sales Order)))-1)
    )
RETURN _result

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Syndicate_Admin
Administrator
Administrator

Dear, this would be the measure to create:

Sales Previous Year = CALCULATE([Sum Sales],DATEADD(Calendar[Date],-1,YEAR))
So you can get the sales of the previous year.

@Syndicate_Admin It shows the total sales amount when place on a card visual. I need to show only last year sales when place on a card visual.

bhelou
Responsive Resident
Responsive Resident

Dear , 

Check this dax if it fits with you , 

Sales Last Year = CALCULATE(
[Sales],
FILTER(
ALL('Date (Sales Order)'),
'Date (Sales Order)'[Order Date] = MAX('Date (Sales Order)'[Order Date]) - 365
)
)


Change the table Name of the dates accordingly 


Please consider accepting this as a solution !! Respect your KUDO !! 
I appreciate your recognition and feel proud to have been able to assist you.


ajve22
Frequent Visitor

@bhelou  Thanks for the suggestion but it doesn't give the correct value and also giving blank on the card visual.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.