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
shavish
Frequent Visitor

Conditions

The below code is not working, the date is returning no value on the coloumn(Looking with actual data, there are logical data to fill the condition)

 

date=IF((AND(condition1=null),(condition2=type)),DATEADD(date,20,year),DATEADD(date,30,year))

 

condition1 is a datatype date, condition 2 is datatype text

 

Also i welcome, if the above function is recommeded to be done in power query or powerbi desktop with add coloumn.

4 REPLIES 4
PwerQueryKees
Post Prodigy
Post Prodigy

Code is not working you say. Where does the variable date come from? 

I also notice that you assign the result also to a variable named date. This is possible, but you can use the new value ONLY in the same let/in context.

Please share your full M code (the complete query) here....

Omid_Motamedise
Memorable Member
Memorable Member

Can you provide the sample and result table?

BA_Pete
Super User
Super User

Hi @shavish ,

 

This may be as simple as using the correct DAX syntax. Try this:

YourColumn =
IF(
    ISBLANK(YourTable[condition1]) && YourTable[condition2] = "Type",
    DATEADD(YourTable[date], 20, YEAR),
    DATEADD(YourTable[date], 30, YEAR)
)

I've assumed 'condition1' and 'condition2' are names of other columns, so replace these accordingly to fit your actual data.

 

However, as per your question, I would almost always recommend adding new columns into Power Query to avoid the calculation needing to be done at runtime, something like this:

YourColumn =
if [condition1] = null and [condition2] = "Type" then Date.AddYears([date], 20)
else Date.AddYears([date], 30)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




PhilipTreacy
Super User
Super User

@shavish 

 

Your explanation isn't very clear and it would really help if you supplied some data.

 

What do condition1=null and condition2=type mean?

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.