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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
nadias
Regular Visitor

Last month data filter in DAX

Hello. I'm new to PowerBI and DAX. Here is my problem of the day.

 

I'm trying to find a way to filter out last caledar month's data from the rest of the data and I need it to work automatically when the year changes. In other words, any time I look at the table, I want to know which rows of my table represent data from the last calendar month. For example, if looking at the data today, July 12, 2017. I want to know which data belong to the month of June 2017. I have a calculated column named DecisionDate that contains dates spanning across the last decade. This is the column I'm trying to filter on.

1 ACCEPTED SOLUTION
fhill
Resident Rockstar
Resident Rockstar

I just posted this for another thread that was looking for something simular.  Hope it helps!  FOrrest

 

Prior_Month = CALCULATE(SUM(Table2[Price]),     // Sum Price
  DATESBETWEEN(Table2[Salesdate],     // Based on Dates Between
  Date(YEAR(EDATE(today(),-1)),MONTH(EDATE(today(),-1)),1),     // Date having Year = Today -1 Month / Month = today -1 Month, and Day = 1
  EOMONTH(today(),-1)))      // End Of Month effective today() -1 month

 

Prior Month.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

5 REPLIES 5
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @nadias,

 

Have you tried the solutions provided above? Does it work in your scenario? If it works, could you accept it as solution to close this thread?

 

If you still have any question on this issue, feel free to post here. Smiley Happy

 

Regards

fhill
Resident Rockstar
Resident Rockstar

I just posted this for another thread that was looking for something simular.  Hope it helps!  FOrrest

 

Prior_Month = CALCULATE(SUM(Table2[Price]),     // Sum Price
  DATESBETWEEN(Table2[Salesdate],     // Based on Dates Between
  Date(YEAR(EDATE(today(),-1)),MONTH(EDATE(today(),-1)),1),     // Date having Year = Today -1 Month / Month = today -1 Month, and Day = 1
  EOMONTH(today(),-1)))      // End Of Month effective today() -1 month

 

Prior Month.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Anonymous
Not applicable

Thank you! I tried to do this with a simple CALCULATE function filtering by previous month(tried it several different ways), and I couldn't get it to work. This worked though.

What happens when it's January and you give it 0 as a month?

 

GilbertQ
Super User
Super User

Hi @nadias

 

You could use the Relative Date Slicer, in which you could then select the "Last" "1" "Months (Calendar)" which would then show you your data for the previous month on your report.

 

Here are more details around the relative date slicer: https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-may-feature-summary/#relativeDateSlicer





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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