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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
utkarsh9771
New Member

LMTD using date slicer selection

Hello Experts!

 

Need help creating a logic
Need to get sales for last month based on the user date selection

For E.g. If I have selected 01-06-2024 and 12-06-2024 in my date slicer, I should get sales from 1th to 12th May.

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the Date column of the Fact Table to the Date column of the Calendar Table.  To your slicer, drag Date from the Calendar Table and select a range of dates.  Write this measure

Sales = sum(Data[Amount])

Sales in same period last month = calculate([Sales],datesbetween(calendar[date],edate(min(calendar[date]),-1),edate(max(calendar[date]),-1)))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the Date column of the Fact Table to the Date column of the Calendar Table.  To your slicer, drag Date from the Calendar Table and select a range of dates.  Write this measure

Sales = sum(Data[Amount])

Sales in same period last month = calculate([Sales],datesbetween(calendar[date],edate(min(calendar[date]),-1),edate(max(calendar[date]),-1)))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Kaviraj11
Super User
Super User

Hi,

You will need to follow these steps:

 

  1. Create a Date Table: Ensure you have a date table in your Power BI model that includes all dates, and it’s marked as a date table.

  2. Establish Relationships: Make sure there’s a relationship between your date table and your sales data table based on the date fields.

  3. Create a New Measure

Sales Last Month =
VAR SelectedStartDate = MIN('Date'[Date])
VAR SelectedEndDate = MAX('Date'[Date])
VAR StartOfLastMonth = EOMONTH(SelectedStartDate, -2) + 1
VAR EndOfLastMonth = EOMONTH(SelectedStartDate, -1)
RETURN
CALCULATE(
SUM('Sales'[Amount]),
FILTER(
ALL('Date'),
'Date'[Date] >= StartOfLastMonth && 'Date'[Date] <= EndOfLastMonth
)
)

 




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

Proud to be a Super User!





I think your solution is going to show results for the entire prior month, whereas the example in the question was if the user selects from the 1st to the 12th of June, the measure should display data from the 1st to the 12th of May.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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