Forum Discussion
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
- camargos88
Community Champion
Hi richard_wylde ,
You can create a date table and work with intel date functions.
https://dax.guide/previousday/
Ricardo
- richard_wylde
Helper 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
Community 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.
- richard_wylde
Helper IV
Thanks v-eachen-msft - this has worked perfectly !