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
BlueTeam1
Frequent Visitor

Start of Month based on Previous Date

Hello,

 

I need some help with some dax. I need to find the first of the TOTALMTD() however it needs to be based on the previous day.


Examples:

  • If I provide the date 10/31/2020, it should provide the TOTALMTD() between 10/1/2020 and 10/30/2020.
  • If I provide 11/1/2020, it should provide 10/1/2020 to 10/31/2020.
  • If I provide 11/2/2020, it provides TOTALMTD() for 11/1/2020.

This is what I have so far:

 

first of month of previous day = var _prev_day = PREVIOUSDAY('Calendar'[Date])
var first_of_month = CALCULATE(STARTOFMONTH('Calendar'[Date]),YEAR('Calendar'[Date]) = YEAR([Previous Date]), MONTH('Calendar'[Date]) = MONTH([Previous Date])
)
return first_of_month

I can't seem to get the filters to work correctly. Any help is appreciated.

1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @BlueTeam1 

VAR end_ = 'Calendar'[Date]-1

VAR start_ = DATE(YEAR(end_), MONTH(end_), 1)

and then you can use those vars in the filter operation  You do not specify if this is to be used in a measure or a calc column. If the former, you´ll need a SELECTEDVALUE( ) in end_

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

 

View solution in original post

1 REPLY 1
AlB
Super User
Super User

Hi @BlueTeam1 

VAR end_ = 'Calendar'[Date]-1

VAR start_ = DATE(YEAR(end_), MONTH(end_), 1)

and then you can use those vars in the filter operation  You do not specify if this is to be used in a measure or a calc column. If the former, you´ll need a SELECTEDVALUE( ) in end_

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

 

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.

Top Solution Authors