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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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
Super User
Super User

@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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@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!:
Power BI Cookbook Third Edition (Color)

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/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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