Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
aavilap
Helper I
Helper I

Help working with previousmonth function

Hello, 

Need help working with Time Intelligence Functions, I'm working with Sales data and trying to compare period over period sales, so to compare to previous month I tried creating a column using the following :

PriorPeriodSales$ = CALCULATE(sum('Sales'[SalesAmount]),PARALLELPERIOD('Sales'[Date],-1,MONTH))  

 

OR

 

PriorPeriodSales$ = CALCULATE(sum('Sales'[SalesAmount]),PREVIOUSMONTH('Calendar'[Date]))

 

in both cases I get a column with no values(no error, just blank), I'm not sure what am I missing. The information on my original table is at a daily level, not sure if that should be a problem?? Please help!

Thanks!

 

4 REPLIES 4
SamTailor
Helper I
Helper I

My solution.

 

Had the same problem - previousmonth returned blanks. Formula syntax was correct but it didnt work. My data was linked to created in Excel calendar ( I'm sure it was perfect, without missing days) but "previousmonth" still didnt work.

 

Solved it by creating new calendar table inside Power Bi using "Calendar" formula. To make it shorter I've cut it at min and max days in my sales table.

 

Calendar = CALENDAR( date(YEAR( Min(Sales[Date]) );1;1);
date(YEAR( MAX(Sales[Date]) );12;31))

Despite that this formula gives 100% the same calendar I created in Excel "previousmonth" started to work perfectly once I linked my data to this new calendar.

 

 

Special thx to the guy who published this video of how to create this Calendar table in Power BI!

https://www.youtube.com/watch?v=F7kc4pd6TVU

fbrossard
Kudo Commander
Kudo Commander

Hi @aavilap,

 

Works good for me.

Make sure :

- your date attribute type is "date" or "datetime"

- all relationships on your date table are marked as single direction

 

 

karthik
Advocate I
Advocate I

I assume you are filtering on the date/month in 'Calendar'[Date] table in which case you need to include ALL('Calendar') as a filter in your calculation.

 

E.g.

 

PriorPeriodSales$ = CALCULATE(SUM('Sales'[SalesAmount]), PREVIOUSMONTH('Calendar'[Date]), ALL('Calendar'))

Greg_Deckler
Community Champion
Community Champion

I am guessing that your issue has to do with the comment from the documentation:

 

"Returns a table that contains a column of all dates from the previous month, based on the first date in the dates column, in the current context."

 

It is relatively likely that the first date in your current context is not what you desire it to be.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.