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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
PowerBIData
Frequent Visitor

How to get the last 6 months from column on a table | Exact dates

Hi,

 

Kindly advise, I have a column with dates and I want to get the exact 6 months from the Original dates to a precision of even a day which will be less than one day from original in order to get exact 6 months. Many Thanks.

 

Original Date |Last 6 Months from Original Date column
  
30/12/202129/06/2021
20/12/202119/06/2021
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @PowerBIData ,

 

Try this:

 

Use M:

Date.AddDays(Date.AddMonths([#"Original Date "], -6),-1)

custom.PNG

 

Use DAX:

Column = EDATE([Original Date ],-6)-1

column.PNG

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @PowerBIData ,

 

Try this:

 

Use M:

Date.AddDays(Date.AddMonths([#"Original Date "], -6),-1)

custom.PNG

 

Use DAX:

Column = EDATE([Original Date ],-6)-1

column.PNG

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

BA_Pete
Super User
Super User

Hi @PowerBIData ,

 

In Power Query M it would be something like this:

 

Date.AddMonths([Original Date], -6)

 

 

In DAX it would be something like this:

 

DATEADD(yourTable[Original Date], -6, MONTH)  

 

 

However, I'm unsure about your definition of "exactly 6 months". The closest you would probably get would be to apply a day adjustment, rather than a month adjustment.

 

Power Query M:

Date.AddDays([Original Date], -182) //This or -183 are as close to half a year as you'll get

 

DAX:

DATEADD(yourTable[Orginal Date], -182, DAY)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.