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
webportal
Impactful Individual
Impactful Individual

Calculate the current date minus 6 months in a DAX measure

I want to calculate the current date minus 6 months in a DAX measure:

MyMeasure = 
DATEADD('Calendar'[Date], -6, MONTH)

Returns a table.

In a matrix where 'Calendar'[Date] is on the rows, this measure returns an error, because the result of the measure is a table and not a scalar.

How to convert this into a scalar?

Thank you

1 ACCEPTED SOLUTION
TheoC
Super User
Super User

@webportal can you adjust your measure to:

Measure = CALCULATE ( MAX ( Calendar[Date] ) , DATEADD ( 'Calendar'[Date] , -6 , MONTH ) )
 
TheoC_0-1634639057875.png

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@webportal Try:

MyMeasure = 
  VAR __Date = MAX('Calendar'[Date])
  VAR __SixMonthsAgo = EOMONTH(__Date,-6)
RETURN
  DATE(YEAR(__SixMonthsAgo),MONTH(__SixMonthsAgo),DAY(__Date))

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
TheoC
Super User
Super User

@webportal can you adjust your measure to:

Measure = CALCULATE ( MAX ( Calendar[Date] ) , DATEADD ( 'Calendar'[Date] , -6 , MONTH ) )
 
TheoC_0-1634639057875.png

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

The EDATE function gives you the date N number of months forward or backward of a reference date. For example, if we start from our sales table and calculate the date of the last sale and we want to calculate the date 6 months before that date the code would be as follows:

closes 6 months ago = EDATE(LASTDATE(Sales[Date]),-6)
Best regards
Carlos Alberto
Pythagoras Data Science

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.