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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Tony67
New Member

How do I create a conditional column by comparing data from two existing columns?

I am new to Power Query and using Power Query to pull data in from an external file.  The data has multiple columns. The two columns, Date and Mine, are the ones that I want to use to create a new conditional column from.  The value for Mine needs to be changed for one value based on whether it is before or after a certain date.

 

An example of the table looks like this

Tony67_0-1712854726850.png

I tried the following to create a new column that I would then use to replace the Existing "Mine" column:

= Table.AddColumn(#"Removed Columns", "Mine1", each if [Mine] <> "OBO" then [Mine] else if [Mine] = "OBO" and [Date] < 01/04/2024 then "OBC" else "OBO")

 

However the code above produces an Expression.Error

Expression.Error: We cannot apply operator < to types Number and Date.

Details:

    Operator=<

    Left=0.001482213

    Right=1/05/2024

 

I am hoping I just have a syntax error but any help is much appreciated.

 

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

use #date to create dates like #date(2024, 04, 01) for April 1st, 2024. Now you compare [Date] value with a result of division of 1 by 4 by 2024 (or whatever you do in your expression) - those are of different types which is not allowed in Power Query M. 

View solution in original post

3 REPLIES 3
Tony67
New Member

Thanks the #date(yyyy,mm,dd) format worked.

wdx223_Daniel
Community Champion
Community Champion

=Table.ReplaceValue(#"Removed Columns",each [Date],null,(x,y,z)=>if x="OBO" and y<#date(2024,4,1) then "OBC" else x,{"Mine"})

AlienSx
Super User
Super User

use #date to create dates like #date(2024, 04, 01) for April 1st, 2024. Now you compare [Date] value with a result of division of 1 by 4 by 2024 (or whatever you do in your expression) - those are of different types which is not allowed in Power Query M. 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.