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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Km93
New Member

Date AddMonths

Hello,

I am trying to using the dates in the left column and add the months listed in the right column to create a new column. Can someone explain what I’m doing wrong?

Thank you!

IMG_1223.png

2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

Hi @Km93 

The issue seems to be a missing else clause.

In M, the syntax of an if expression must be

if <if-condition> then <true-expression> else <false-expression>

For example, if you want to return null when the condition is false, you could write:

if [Contact Frequency] = 1 then Date.AddMonths([Last Contact Attempt],1) else null

See here for more examples/discussion:

https://bengribaudo.com/blog/2020/01/06/4844/power-query-m-primer-part14-control-structure#condition...

 

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

rohit1991
Super User
Super User

hi @Km93 ,

Use this corrected formula to handle the text and numeric parts in Contact Frequency:

 


if Text.Contains([Contact Frequency], "mo") then
Date.AddMonths([Last Contact Attempt], Number.FromText(Text.BeforeDelimiter([Contact Frequency], " ")))
else
null



It extracts the numeric value before "mo" and applies Date.AddMonths accordingly.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

5 REPLIES 5
v-hashadapu
Community Support
Community Support

Hi @Km93, Hope your issue is solved. If it is, please consider marking the answer 'Accept as solution', so others with similar issues may find it easily. If it isn't, please share the details.
Thank you.

v-hashadapu
Community Support
Community Support

Hi @Km93, Hope your issue is solved. If it is, please consider marking the answer 'Accept as solution', so others with similar issues may find it easily. If it isn't, please share the details.
Thank you.

v-hashadapu
Community Support
Community Support

Hi @Km93 , Hope your issue is solved. If it is, please consider marking the answer 'Accept as solution', so others with similar issues may find it easily. If it isn't, please share the details. Thank you.

rohit1991
Super User
Super User

hi @Km93 ,

Use this corrected formula to handle the text and numeric parts in Contact Frequency:

 


if Text.Contains([Contact Frequency], "mo") then
Date.AddMonths([Last Contact Attempt], Number.FromText(Text.BeforeDelimiter([Contact Frequency], " ")))
else
null



It extracts the numeric value before "mo" and applies Date.AddMonths accordingly.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
OwenAuger
Super User
Super User

Hi @Km93 

The issue seems to be a missing else clause.

In M, the syntax of an if expression must be

if <if-condition> then <true-expression> else <false-expression>

For example, if you want to return null when the condition is false, you could write:

if [Contact Frequency] = 1 then Date.AddMonths([Last Contact Attempt],1) else null

See here for more examples/discussion:

https://bengribaudo.com/blog/2020/01/06/4844/power-query-m-primer-part14-control-structure#condition...

 

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.