Forum Discussion
sales amount difference between two dates
To achieve this, you can use a combination of DAX functions in Power BI. Here's a step-by-step guide:
Cumulative Sales Measure:
First, create a measure that calculates the cumulative sales for each month up to the current date in the context of the visual.
Cumulative Sales =
CALCULATE(
SUM(Table[Sales]),
FILTER(
ALL(Table[fecha registro]),
Table[fecha registro] <= MAX(Table[fecha registro]) &&
MONTH(Table[fecha registro]) = MONTH(MAX(Table[fecha registro]))
)
)
Difference from Previous Date Measure:
To show the difference from the previous date, you can use the following measure:
Sales Difference =
[Cumulative Sales] -
CALCULATE(
[Cumulative Sales],
DATEADD(Table[fecha registro], -1, DAY)
)
Percentage Difference Measure:
To show the percentage difference, you can use the following measure:
% Difference =
IF(
CALCULATE([Cumulative Sales], DATEADD(Table[fecha registro], -1, DAY)) <> 0,
[Sales Difference] / CALCULATE([Cumulative Sales], DATEADD(Table[fecha registro], -1, DAY)),
BLANK()
)
Visualizing the Data:
Drag the fecha registro field to the rows of a matrix visual.
Drag the Month field to the columns of the matrix visual.
Add the Sales Difference and % Difference measures to the values area of the matrix visual.
This will give you a matrix that shows the sales difference for each date by month, and the percentage difference from the previous date.