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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

Help needed with data preparation (using M)

Hey ppl!

I've received a new task and need to learn M fast.

Problem is, I have a "simple" problem to solve but didn't learn enough M yet to solve it in a timely manner.

Hope you guys can help.

 

I have a table called "Update" with a single column "When" and single row containing one date.

Like this:


TABLE Update
When
28/02/2020

 

This date is dynamic, obtained by a query.

 

I have a second table "Water_Consumption" with a date column "Reading" and a column named "m3" formatted as number (integer). Like this:


TABLE Water_Consumption
Reading                m3
22/12/2019          210
22/01/2020          208
22/02/2020             0
22/03/2020             0
22/04/2020             0

 

My problem:
I need to change 0 to null when the date is greater than the date in "When".

So in the current example, my Water_Consumption table would look like:


TABLE Water_Consumption
Reading          m3
22/12/2019     210
22/01/2020     208
22/02/2020        0
22/03/2020     null
22/04/2020     null

 

This is as far as I could go, it works but requires me a manual update every month:

 

Table.ReplaceValue(#"Previous_step", each [m3], each if [Reading] <= #date(2020, 2,28) then [m3] else null, Replacer.ReplaceValue, {"m3"} )

 

Problem is, I need to make it update automatically so my current "solution" doesn't cut it.

 

Can you guys please advise?

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

it seems like you are taking on the advanced editor in Power Query. Perhaps an easier way to do this is to first create a new column with the value from Update, and then create another column according to the logic you have. Once that is completed you can remove the original m3-column and the When-column.

 

If you still want to do this in Advanced editor, I think this will work for you:

= Table.ReplaceValue(#"Previous step", each [m3], each if [Reading] <= List.First(Update[When]) then [m3] else null, Replacer.ReplaceValue, {"m3"} )

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

View solution in original post

2 REPLIES 2
sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

it seems like you are taking on the advanced editor in Power Query. Perhaps an easier way to do this is to first create a new column with the value from Update, and then create another column according to the logic you have. Once that is completed you can remove the original m3-column and the When-column.

 

If you still want to do this in Advanced editor, I think this will work for you:

= Table.ReplaceValue(#"Previous step", each [m3], each if [Reading] <= List.First(Update[When]) then [m3] else null, Replacer.ReplaceValue, {"m3"} )

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Anonymous
Not applicable

Thanks mate, your solution solved the issue!

 

Also thanks for your suggestion, I believe it would be an easier way to solve the problem but I was afraid the impact in performance would hurt the model as a whole - that's why I opted to use the editor and dedicate an effort to learn M.

 

 

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.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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