Forum Discussion
Calculate current order level versus previous months average
BugmanJ ,
sorry , can you try this?
PercentDifference =
VAR CurrentDay = DAY(TODAY()) -- Get the current day
VAR CurrentMonth = MONTH(MAX(DateTable[Date])) -- Get the current month
VAR CurrentYear = YEAR(MAX(DateTable[Date])) -- Get the current year
-- Running total for the current month up to the current day
VAR CurrentMonthOrders =
CALCULATE(
SUM(Sales[Orders]),
FILTER(
Sales,
YEAR(Sales[Date]) = CurrentYear &&
MONTH(Sales[Date]) = CurrentMonth &&
DAY(Sales[Date]) <= CurrentDay
)
)
-- Average running total for the same day across previous months
VAR AverageOrdersUpToDay =
AVERAGEX(
FILTER(
ALL(DateTable),
(YEAR(DateTable[Date]) < CurrentYear) ||
(YEAR(DateTable[Date]) = CurrentYear && MONTH(DateTable[Date]) < CurrentMonth)
),
CALCULATE(
SUM(Sales[Orders]),
FILTER(
Sales,
DAY(Sales[Date]) = CurrentDay &&
YEAR(Sales[Date]) = YEAR(DateTable[Date]) &&
MONTH(Sales[Date]) = MONTH(DateTable[Date])
)
)
)
-- Calculate the percentage difference
RETURN
IF(
AverageOrdersUpToDay > 0,
DIVIDE(CurrentMonthOrders, AverageOrdersUpToDay, 0) * 100,
BLANK()
)
output:
For August 5th:
Running Total: Current month (August) = 40.
Average Running Total: Previous months = 30+35+403=35\frac{30 + 35 + 40}{3} = 35330+35+40=35.
Percent Difference: 4035×100=114.2%\frac{40}{35} \times 100 = 114.2\%3540×100=114.2%.
Please mark this as solution if it helps. Appreciate Kudos.
Whilst your maths is correct, the actual equation above gives some very large numbers!!!
I have edited the above request with a link to a file! Hope this helps