Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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
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.
Solved! Go to Solution.
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.
Thanks the #date(yyyy,mm,dd) format worked.
=Table.ReplaceValue(#"Removed Columns",each [Date],null,(x,y,z)=>if x="OBO" and y<#date(2024,4,1) then "OBC" else x,{"Mine"})
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.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
9 | |
7 | |
6 | |
6 |