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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

M Code: Create new column that populates with last day of current month

Hi,

 

I'm bringing in a delimited text file/table in to Power BI.  This table has medical eligibility data (names, blood type, age, and medical insurance coverage dates).

 

One of the fields is named [Coverage End Date].  This column is usually populated with a date that I can work with however it is sometimes left blank if an employee is still with the company (if the employee is still with the company it is impossible to know when their medical insurance eligibility will end).  Here is an example of the data:

 

Member ID    Name               Age     Coverage Start Date     Coverage End Date

0100              Jim Kelly           50        1/20/2010                    5/30/2018

0202              Tim Tebow       20        4/15/2008                    9/3/2010

0555              John Elway       55        2/19/2006                  

0177              Tom Brady       96        6/10/2011                    6/3/2019

 

I would like to create a new column (using Power Query while using M Code) that essentially does the following:

If [Coverage End Date] has a date, then use that date but if [Coverage End Date] is empty use the last date of the current month.  For example, I'd need John Elway's [Coverage End Date] to populate with 9/30/2020 if ran today.

 

This dashboard and the tables will be refreshed several times throughout the month and many times througout the year so I need this new column to have this new date column fluid.

 

 

Any ideas?

Thank you!

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Perhaps:

End =
  if [Coverage End Date] <> null then [Coverage End Date] else Date.EndOfMonth([Coverage End Date])


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@Anonymous - Perhaps:

End =
  if [Coverage End Date] <> null then [Coverage End Date] else Date.EndOfMonth([Coverage End Date])


Follow on LinkedIn
@ 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!:
DAX For Humans

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

@Anonymous , Try like

if [Coverage End Date] = null then Date.EndOfMonth(DateTime.LocalNow()) else [Coverage End Date]

 

http://excel-inside.pro/blog/2018/05/17/comparing-null-values-in-power-query/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors