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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
uthall
Helper II
Helper II

Previous Month

Hello,

 

I have a table with data and dates.

 

I simply want to show a card of the last 1 months data.

 

What is the DAX syntax for this?

 

Thanks

Jeff

1 ACCEPTED SOLUTION
v-caliao-msft
Employee
Employee

Hi @uthall,

 

Do you need aggregate value or detail value? If you need aggregate value for pervious month, you can use PREVIOUSMONTH to achieve this requirement, here is the sample DAX for you reference.
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSMONTH('DateTime'[DateKey])) 
https://msdn.microsoft.com/en-us/library/ee634758.aspx?f=255&MSPPError=-2147217396

 

Regards,

Charlie Liao

View solution in original post

6 REPLIES 6
v-caliao-msft
Employee
Employee

Hi @uthall,

 

Do you need aggregate value or detail value? If you need aggregate value for pervious month, you can use PREVIOUSMONTH to achieve this requirement, here is the sample DAX for you reference.
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSMONTH('DateTime'[DateKey])) 
https://msdn.microsoft.com/en-us/library/ee634758.aspx?f=255&MSPPError=-2147217396

 

Regards,

Charlie Liao

Greg_Deckler
Super User
Super User

Typically, you would create a column like so:

 

Column = MONTH(TODAY()) - MONTH(Table[Date])

And then just filter to 1 or 2 depending upon your definition of "last".


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks,

 

What if TODAY() is Jan 2017, making the previous month DEC 2016?

 

The return value will be 1-12 = 11 (seems to be an absolute value)

 

This is also the case if i want Next Month, which is tghe reverse of the above

 

Any further ideas?

 

 

I have just resolved this with the following formula.

 

PrevMonth = if(Month(today()) = 1, if(year(GP[Month]) & month(GP[Month]) = year(today())-1 & month(today())+11, 1, 0), if(year(GP[Month]) & month(GP[Month]) = Year(today()) & (Month(today()-1)), 1, 0)) 

tjd
Impactful Individual
Impactful Individual

Thanks for the equation, but you need an extra set of parentheses around MONTH, YEAR, etc. wherever you are doing your math, such as "(YEAR(TODAY())-1) & (MONTH(TODAY())+11)" and "& (Month(TODAY())-1)".  If not, it will not compute correctly.

G'day, 

 

I have used the following formula in Excel to identify the previous month,  it works also for January.

 

=IF(MONTH(TODAY())=MONTH(1),IF(AND(MONTH(C13)=MONTH(TODAY())+11,YEAR(C13)=YEAR(TODAY())-1),1,0),IF(AND(MONTH(C13)=MONTH(TODAY())-1,YEAR(C13)=YEAR(TODAY())),1,0))

 

This formula, however, is not working in Power BI, if anyone can enlighten me to why i would appreciate it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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