Forum Discussion

ajve22's avatar
ajve22
Frequent Visitor
3 years ago

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

  • bhelou's avatar
    bhelou
    Icon for Responsive Resident rankResponsive 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's avatar
      ajve22
      Frequent Visitor

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

  • 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.
    • ajve22's avatar
      ajve22
      Frequent Visitor

      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.

  • Arul's avatar
    Arul
    Icon for Super User rankSuper 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