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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
tagban
Helper I
Helper I

Compare 2 dates to determine same month

I'm trying to write a DAX measure and having errors when trying to compare two dates. I had found some answers here in the past for other issues I ran into but am relatively new to DAX and M. Basically I want to determine if two column's dates are within the same month. The second column has NULL Values if they don't have a date associated with that yet. 

So originally I was going to use DateDiff using STARTOFMONTH[Date1], vs STARTOFMONTH[Date2]. That way I could see if there was any difference and make it insanely simple.

Problem is Date2 often has NULL values (As its expected to), basically checking to see if someone registered and then un-registered within the same month. Any help is appreciated.

DateDiff(STARTOFMONTH(Registration[enroll_start_date]), STARTOFMONTH(Registration[disenroll_date]),MONTH)

If this would be better in PowerQuery I'm not opposed to it. Just going with the stuff I understand better first. 
1 ACCEPTED SOLUTION
tagban
Helper I
Helper I

I actually found a solution, creating a new COLUMN:
Same Month Unregister = SWITCH(True,Month(Query1[register_date]) == Month(Query1[unregister_date]) && Year(Query1[register_date]) == Year(Query1[unregister_date]), "Yes"1=1"No")

View solution in original post

3 REPLIES 3
tagban
Helper I
Helper I

I actually found a solution, creating a new COLUMN:
Same Month Unregister = SWITCH(True,Month(Query1[register_date]) == Month(Query1[unregister_date]) && Year(Query1[register_date]) == Year(Query1[unregister_date]), "Yes"1=1"No")

rsbin
Super User
Super User

@tagban ,

Personally, would use the MONTH function.  Create a calculated column:

SameMonth = SWITCH(
                TRUE()
                ISBLANK([Column2]), 0,  //or whatever you need to enter here
                MONTH([Column1]) = Month([Column2]), "SameMonth" ) //or whatever

Trust something like this will work for you.

Regards,

 

I wound up finding a solution using a new Column. Probably not the most elegant and yours actually works as well, but I also have to compare year since this is 9 years of data to look back on. Thank you so much for offering assistance!

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.