Hi Dhruvin
I want the DAX for calculating previous month sales in sales fact table without date column and having only year and month column in the table
Also it should handle if month is 1 then previous month: 12 and not 0
Regards
Arun
Hi Dhruvin
I want the DAX for calculating previous month sales in sales fact table without date column and having only year and month column in the table
Also it should handle if month is 1 then previous month: 12 and not 0
Regards
Arun
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amira BedhiafiRank #601 · 4K reputationPosted Sep 29, 2025, 9:34 AM EDT
Hello Dhruvin !
I would recommend that you add a proper date column in your case, meanwhile you need to capture the selected year or month context from your table or slicer and if
month= 1, you go toDecemberof the previous year otherwise, you just subtract 1 from the current month.If you need a running trend across monthsit’s better to create a YearMonth key (like
202501) and calculate relative offsets usingMAX orMINor a proper date table.Previous Month Sales = VAR CurrentYear = SELECTEDVALUE ( Sales[Year] ) VAR CurrentMonth = SELECTEDVALUE ( Sales[Month] ) VAR PrevYear = IF ( CurrentMonth = 1, CurrentYear - 1, CurrentYear ) VAR PrevMonth = IF ( CurrentMonth = 1, 12, CurrentMonth - 1 ) RETURN CALCULATE ( SUM ( Sales[SalesAmount] ), Sales[Year] = PrevYear, Sales[Month] = PrevMonth )