Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi!
I have a date table where I've created a column with the DAX line below to give me a true/false value if the date is last month. I'm taking the month number of today's date and subtracting 1, and using if(and to match against the month number and year of dates in my table. This is working great as currently all sepetember 2020 dates show True, everything else shows False. My problem will be come January the DAX will calculate "0" as the month number. What can I add to this DAX to account for this and get it to return "12" instead of "0". I'm sure there is a fairly simple way to do this, I'm just not seeing it and need a fresh set of eyes! Thanks!
Last Month? = IF(AND(MONTH(TODAY()) -1 = DateTable[Month Num],YEAR(TODAY()) = DateTable[Year]),TRUE(),FALSE())
Solved! Go to Solution.
Hi @rbreneman
Try this
Last Month? =
var __ThisMonth = MONTH(TODAY())
var __ThisYear = YEAR(TODAY())
var __LastMonth = IF(__ThisMonth = 1, 12, __ThisMonth - 1)
var __LastMonthYear = IF(__ThisMonth = 1, __ThisYear - 1, __ThisYear)
return
IF (
AND (
DateTable[Month Num] = __LastMonth,
DateTable[Year] = __LastMonthYear
),
TRUE (),
FALSE ()
)
Hope this helps
David
Hi @rbreneman
Try this
Last Month? =
var __ThisMonth = MONTH(TODAY())
var __ThisYear = YEAR(TODAY())
var __LastMonth = IF(__ThisMonth = 1, 12, __ThisMonth - 1)
var __LastMonthYear = IF(__ThisMonth = 1, __ThisYear - 1, __ThisYear)
return
IF (
AND (
DateTable[Month Num] = __LastMonth,
DateTable[Year] = __LastMonthYear
),
TRUE (),
FALSE ()
)
Hope this helps
David
Thanks so much! That works perfectly. Huge help! I appreciate you laying it out like that too, I tend to write in one line but it certainly helps to understand it when it's broken out on multiple lines.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 9 | |
| 9 | |
| 8 | |
| 6 | |
| 6 |
| User | Count |
|---|---|
| 24 | |
| 20 | |
| 20 | |
| 14 | |
| 14 |