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
Anonymous
Not applicable

Get First day last 2 month

Hi all,

 

I currently have the below DAX to get the First day of the last 2nd month. I mean, when i select 4-Nov-2020 this gives date as 1-Oct-2020 which is correct. 

 

last 2 months = EDATE ( EOMONTH ( SELECTEDVALUE(Query1[STARTDATE] ), 0 ), -2 ) + 1

 

But when i select a date 25-Sep-2020 this gives date as 31-Jul-2020 instead of 1-Aug-2020.

 

I know this behaviour is because we are adding 1 day at the end. But any idea how can i get 1-Aug-2020?

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try to use DATESBETWEEN to create a measure like so:

Measure =
CALCULATE (
    AVERAGE ( 'Table'[Value] ),
    ALL ( 'Table' ),
    DATESBETWEEN ( 'Table'[Date], [Last 2 month], [End of last month] )
)

 

 

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

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous ,

 

Try like

EOMONTH ( SELECTEDVALUE(Query1[STARTDATE] ), -2 )+ 1

Anonymous
Not applicable

@amitchandak thanks Amit

 

I have another question with respect to the same date. 

 

I need to calculate the Avg(bill)for the period between these two measures
 
Last 2 month = EOMONTH ( SELECTEDVALUE(Query1[STARTDATE] ), -2 )+ 1
End of last month = EOMONTH (SELECTEDVALUE(Query1[STARTDATE]), 1 )
 
I'm not able to pass these dates in the DATESINPERIOD function.
 
Kindly help me.
 
 
 
 
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try to use DATESBETWEEN to create a measure like so:

Measure =
CALCULATE (
    AVERAGE ( 'Table'[Value] ),
    ALL ( 'Table' ),
    DATESBETWEEN ( 'Table'[Date], [Last 2 month], [End of last month] )
)

 

 

Best Regards,

Icey

 

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

Anonymous
Not applicable

@Icey Thanks Icey, 

 

I will try it today. 

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.