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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Conditional replacing of dates

Hello,

 

I am trying to replace dates in column "BASELINE Start Date" with a date of 1 Jan 2000 based on if the value in column "RAG Number" = 4. See querry below. It is not working somehow...

Any help much appreciated!

 

= Table.ReplaceValue(#"Renamed Columns2",each[BASELINE Start Date], each if [RAG Number] = "4" then [BASELINE Start Date] = #date(2000, 1, 1) else [BASELINE Start Date], Replacer.ReplaceValue,{"BASELINE Start Date"})

1 ACCEPTED SOLUTION

 

Perhaps your [RAG Number] column is number type, not text type?

Try changing this:

each if [RAG Number] = "4" >> each if [RAG Number] = 4   // No quotes for number types

 

Pete



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

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Try removing the second explicit reference to your column like this. You've laready identified the column to affect in the second argument, so you shouldn't need to declare it again:

= Table.ReplaceValue(
    #"Renamed Columns2",
    each [BASELINE Start Date],
    each if [RAG Number] = "4" then #date(2000, 1, 1) else [BASELINE Start Date],         
    Replacer.ReplaceValue,{"BASELINE Start Date"}
)

 

If that doesn't work, try changing the Replacer type:

Replacer.ReplaceValue >> Replacer.ReplaceText

 

Pete



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

Proud to be a Datanaut!




Anonymous
Not applicable

Thanks for the feedback. I have tried, but unfortunatly no luck.

 

Perhaps your [RAG Number] column is number type, not text type?

Try changing this:

each if [RAG Number] = "4" >> each if [RAG Number] = 4   // No quotes for number types

 

Pete



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

Proud to be a Datanaut!




Anonymous
Not applicable

Hi BA_Pete,

 

Great! This indeed solved the problem. Many thanks!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors