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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Centaur1
Regular Visitor

Compare 2 date fields and use Greater than date

Hello,

 

I am a novice user of PQ. 

I need to compare 2 dates I have:

Date1 and Date2

If Date2>=Date1 then use Date2 else use Date1

I added a conditional column but I think the issue is that I need to handle NULLS on Date2 but not sure how to do this.  

here is the Custom column I added:

= Table.AddColumn(#"Reordered Columns", "Custom", each if [Date1] >= [Date2] then [Date2] else [Date1])

 

If Date2 is NULL then use Date1 is how I need to handle NULLS.

 

thank you

 

1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@Centaur1 Try:

= Table.AddColumn(
#"Reordered Columns",
"Custom",
each
if [Date2] = null then [Date1]
else if [Date2] >= [Date1] then [Date2]
else [Date1]
)

 

BBF

View solution in original post

3 REPLIES 3
dufoq3
Super User
Super User

Hi @Centaur1, another solution:

 

dufoq3_1-1737825947716.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLQNzTUNzIwMlHSUTK0hHNidaKVDE2R5CAixlARU5BqczgnNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date1 = _t, Date2 = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date1", type date}, {"Date2", type date}}),
    Ad_MaxDate = Table.AddColumn(ChangedType, "MaxDate", each List.Max( { [Date2] ?? [Date1], [Date1] } ), type date)
in
    Ad_MaxDate

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Centaur1
Regular Visitor

BBF, that was perfect!  thank you very much.  

BeaBF
Super User
Super User

@Centaur1 Try:

= Table.AddColumn(
#"Reordered Columns",
"Custom",
each
if [Date2] = null then [Date1]
else if [Date2] >= [Date1] then [Date2]
else [Date1]
)

 

BBF

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors
Top Kudoed Authors