Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have aggregated the monthly sales from my salesorder table to a table containing the monthly sales information. What I'm trying to do is create a column that references the monthly sales from the previous year to show the monthly change.
This is a model of what I have so far:
Month | Year | ThisMonthSales |
January | 2018 | $1000 |
January | 2019 | $2000 |
January | 2020 | $3000 |
January | 2021 | $4000 |
February | 2019 | $1500 |
February | 2020 | $2500 |
This is what I'd like to create:
Month | Year | ThisMonthSales | LastYearMonthSales |
January | 2018 | $1000 | |
January | 2019 | $2000 | $1000 |
January | 2020 | $3000 | $2000 |
January | 2021 | $4000 | $3000 |
February | 2019 | $1500 | |
February | 2020 | $2500 | $1500 |
I tried this command, but the issue I'm running into is that the calculated column contains the yearly aggregated sales instead of the monthly sales:
Column =
VAR Last_Year = 'Table'[Year] - 1
RETURN
CALCULATE(SUM('Table'[This Month Sales]), ALL('Table'), 'Table'[Year] = Last_Year, 'Table'[Month] = 'Table'[Month])
What's the best way for me to accomplish this?
Solved! Go to Solution.
@gsmith_eqd
please try
Column =
VAR Last_Year = 'Table'[Year] - 1
RETURN
CALCULATE (
SUM ( 'Table'[This Month Sales] ),
ALLEXCEPT ( 'Table', 'Table'[Month] ),
'Table'[Year] = Last_Year
)
@gsmith_eqd
please try
Column =
VAR Last_Year = 'Table'[Year] - 1
RETURN
CALCULATE (
SUM ( 'Table'[This Month Sales] ),
ALLEXCEPT ( 'Table', 'Table'[Month] ),
'Table'[Year] = Last_Year
)
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
30 | |
13 | |
11 | |
9 | |
6 |