cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EMH Frequent Visitor
Frequent Visitor

SQL query to include date range of last 6 months but starting on the 1st.

I am using PBI Import from SQL Server Database to pull data for the last six months but want the start date to always be the 1st: of the month through today.  This is what I have right now:

Task.CreatedDate >=DATEADD(mm, DATEDIFF(m,0,DATEADD(m,-6,GETDATE())),0)

 

I did not want a partial month except for the current so for example, if I were to refresh the query today and anytime the rest of the month  I would want to include April 1st through current day.  Then in November the query would return May 1st through the current day.

Looking for help to complete the SQL Condition if possible.

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
EMH Frequent Visitor
Frequent Visitor

Re: SQL query to include date range of last 6 months but starting on the 1st.

Sorry, ended up not needing to do this but thanks for answering!

 

View solution in original post

3 REPLIES 3
Highlighted
Ross73312 Super Contributor
Super Contributor

Re: SQL query to include date range of last 6 months but starting on the 1st.

Best bet would be to simply use the function Start of Month

 

https://msdn.microsoft.com/en-us/query-bi/m/date-startofmonth

 

Pass it the date you wish, and it will return the 1st.


   

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

Proud to be a Datanaut!


   


EMH Frequent Visitor
Frequent Visitor

Re: SQL query to include date range of last 6 months but starting on the 1st.

Sorry, ended up not needing to do this but thanks for answering!

 

View solution in original post

v-danhe-msft Super Contributor
Super Contributor

Re: SQL query to include date range of last 6 months but starting on the 1st.

Hi @EMH,

It's pleasant that your problem has been solved,  could you please mark an answer to close this topic if possible?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 355 members 3,688 guests
Please welcome our newest community members: