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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
robtops
New Member

Power Query If date is between 2 other dates with null values Problems with Null Values

I've been searching all over the place for a solution to what I though should be pretty simple but still can't get it to work. In Oracle my query looks like:

Case when first_reminder_expected_date between NVL(Entry_date, '30-Dec-9999') and NVL(Exit_Date,'31-DEC-9999')

 

I'm sure I'm doing something pretty basic wrong but can't seem to figure it out.  All the date columns contain nulls so the formula needs to deal with this

 

Any advice on how to achieve the same result in Power Query would be much appreciated Thanks

 

Rob

1 ACCEPTED SOLUTION

Hi @robtops,

 

I agree with BhaveshPatel’s point of view, you can use Table.ReplaceValue function to achieve your requirement.
 

Capture.PNG

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Area table.xlsx"), null, true),
    Sheet3_Sheet = Source{[Item="Sheet3",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet3_Sheet),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Entry_date", type date}, {"Exit_Date", type date}}),
    Custom=
let
    #"replace Entry_date" = Table.ReplaceValue(#"Changed Type",null,#date(9999, 12, 30),Replacer.ReplaceValue,{"Entry_date"}),
    #"replace Exit_Date" = Table.ReplaceValue(#"replace Entry_date",null,#date(9999, 12, 31),Replacer.ReplaceValue,{"Exit_Date"})
in
    #"replace Exit_Date"
in
Custom

 

Capture2.PNG


Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

10 REPLIES 10
BhaveshPatel
Community Champion
Community Champion

Can you please elaborate your scenario what are you trying to do using powerquery.

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

I'm trying to create a flag which will tell me if the field 'First_Reminder_Expected_Date' is between the other two fields 'Entry_Date' and Exit_Date.  This will be used a in a slicer / filter in a dashboard I'm creating

 

Do you need any more info?

You can create a conditional column in PowerQuery.

 

s1.PNGR

To deal with the null values there are quite a few workarounds such as you can use replace values option or fill down option as well to deal with the null values.

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Thanks very much.  I really wanted to be able to to combine it in other if statements as well if possible e.g

 

if first_reminder_expected_date between Entry_date and Exit_Date

and ColumnA = "yes"

then "A" else "B"

 

is this possible in one query or do i need to do it in 2 stages?

Yes you can do it in the same query as long as Column A is in the same table.

 

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Thanks a lot for your help, hopefully I should be abel to progress with this now

Sorry i'm still getting a problem with Nulls.

 

I can't really replace the Nulls in all the columns as the indicate that something hasn't reached that stage.

 

Is there a way to deal with them in a formula e.g if null or NVL?

Hi @robtops,

 

I agree with BhaveshPatel’s point of view, you can use Table.ReplaceValue function to achieve your requirement.
 

Capture.PNG

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\Area table.xlsx"), null, true),
    Sheet3_Sheet = Source{[Item="Sheet3",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet3_Sheet),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Entry_date", type date}, {"Exit_Date", type date}}),
    Custom=
let
    #"replace Entry_date" = Table.ReplaceValue(#"Changed Type",null,#date(9999, 12, 30),Replacer.ReplaceValue,{"Entry_date"}),
    #"replace Exit_Date" = Table.ReplaceValue(#"replace Entry_date",null,#date(9999, 12, 31),Replacer.ReplaceValue,{"Exit_Date"})
in
    #"replace Exit_Date"
in
Custom

 

Capture2.PNG


Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

You have to use replace values or fill down feature for replacing nulls.

 

 

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

If you think the problem is solved, please mark this post as solution.

 

 

Thank you for your appreciation.

 

Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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