Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello, Power BI Community
I have a Data set like below.
I want to show Previous month value for each state (In this case WA and NY) so I wrote below DAX.
Solved! Go to Solution.
Hi @PeraZo ,
The usage of PREVIOUSMONTH requires the Filter context and, for that reason should be used in a measure instead of a calculated column.
If, do to some business logic, you really need to create a calculated column for this, you should do:
var PreviousDate = IF( MONTH('Sheet1'[YearMonth]) = 1 ,
//if the previous month is last year
DATE(YEAR('Sheet1'[YearMonth])-1,MONTH('Sheet1'[YearMonth])-1,1),
//if the previous month is this year
DATE(YEAR('Sheet1'[YearMonth]),MONTH('Sheet1'[YearMonth])-1,1)
)
return CALCULATE(SUM('Sheet1'[Sale]),FILTER('Sheet1', 'Sheet1'[YearMonth] = PreviousDate))
Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudo 👍
Thanks!
You can also check out my LinkedIn!
Best regards,
Jorge Pessoa
Hi,
You should first of all create a Date Table with calculated column formulas for Year, Month name and Month number. Sort the Month name by the Month number. Write your formula as a measure (not as a calculated colummn). Furthermore, revise that measure to:
Previousmonth = CALCULATE(SUM('Sheet1'[Sale]),PREVIOUSMONTH(Calendar[Date]))
Hope this helps.
Hi @PeraZo ,
The usage of PREVIOUSMONTH requires the Filter context and, for that reason should be used in a measure instead of a calculated column.
If, do to some business logic, you really need to create a calculated column for this, you should do:
var PreviousDate = IF( MONTH('Sheet1'[YearMonth]) = 1 ,
//if the previous month is last year
DATE(YEAR('Sheet1'[YearMonth])-1,MONTH('Sheet1'[YearMonth])-1,1),
//if the previous month is this year
DATE(YEAR('Sheet1'[YearMonth]),MONTH('Sheet1'[YearMonth])-1,1)
)
return CALCULATE(SUM('Sheet1'[Sale]),FILTER('Sheet1', 'Sheet1'[YearMonth] = PreviousDate))
Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudo 👍
Thanks!
You can also check out my LinkedIn!
Best regards,
Jorge Pessoa
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
126 | |
78 | |
77 | |
60 | |
52 |
User | Count |
---|---|
165 | |
86 | |
68 | |
68 | |
58 |