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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Advocate V
Advocate V

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
Super User
Super User

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.

 


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.