Forum Discussion

richard_wylde's avatar
richard_wylde
Icon for Helper IV rankHelper IV
6 years ago
Solved

previous days sales

Hello,

 

I have a table with the following columns :- company_name,  sales_date,  sales_amount

I need another column showing the percentage change of sales_amount from the previous day, is there a simple way to do this ?

 

  • Hi richard_wylde ,

     

    You could refer to the following DAX:

    Measure =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        DATEADD ( 'Table'[Date], -1, DAY ),
        ALLEXCEPT ( 'Table', 'Table'[Name] )
    )

    Here is my test file for your reference. As to date column, you could create a date table to make relationships.

     

4 Replies

    • richard_wylde's avatar
      richard_wylde
      Icon for Helper IV rankHelper IV

      Thanks camargos88 , I can find the previous day  using  previous_day = DATEADD(LASTDATE(Table1[the_date].[Date]),-1,DAY)

       

      but how do I find the sales for the previous day ?
       
      This is the nearest I can get, however it sums the previous day value for all the companies rather than each of the companies -
       
      xxx = CALCULATE(sum('Table1'[Sales]),
                 FILTER('Table1','Table1'[the_date].[Year] = 'Table1'[the_date].[Year]),
                 FILTER('Table1','Table1'[the_date].[Month] = 'Table1'[the_date].[Month]),
                 FILTER('Table1','Table1'[company_name] = 'Table1'[company_name]),
       DATEADD(LASTDATE(Table1[the_date].[Date]),-1,DAY))
       
       
       
       
       
       
       
       
       
       
       
       
       
       
  • v-eachen-msft's avatar
    v-eachen-msft
    Icon for Community Support rankCommunity Support

    Hi richard_wylde ,

     

    You could refer to the following DAX:

    Measure =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        DATEADD ( 'Table'[Date], -1, DAY ),
        ALLEXCEPT ( 'Table', 'Table'[Name] )
    )

    Here is my test file for your reference. As to date column, you could create a date table to make relationships.