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

Join 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.

Reply
Anonymous
Not applicable

Null values in table replaced with 0 return blank cell from calculation??

Hi I have a table created by merging data some of cells return Null ihave changed these to 0 with the replace function, hoping that the 0 would be used in  a calculation within Power Query. but when the Query is closed and loaded the Null are replaced in the table by 0 but the column that returns the sum of the calculation is still blank?? any ideas how i can get around this please??

 

 

let

Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Part", type text}, {"Forecast", Int64.Type}, {"Forecast qty RT - MAR", Int64.Type},
{"Stock Total", Int64.Type}, {"On order (BF required date)", Int64.Type}, {"J24 Quantity", Int64.Type}}),

#"Grouped Rows" = Table.Group(#"Changed Type", {"Part"}, {
{"Tables", (t)=>
let
//lists to compute running stock total
fq = t[#"Forecast qty RT - MAR"],
oo = t[#"On order (BF required date)"],

#"rtList" = List.Generate(
()=>[rt=t[Stock Total]{0} - fq{0} + oo{0}, idx=0],
each [idx] < List.Count(fq),
each [rt= if oo{[idx]} <> oo{[idx]+1}
then [rt] - fq{[idx]+1} + oo{[idx]+1}
else [rt] - fq{[idx]+1},
idx=[idx]+1],
each [rt]),

//combine running total column with original table
#"Result" = Table.FromColumns(
{t[Part]}
& {t[Forecast]}
& {fq}
& {#"rtList"}
& {t[Stock Total]}
& {oo}
& {t[J24 Quantity]},
{ "Part",
"Forecast",
"Forecast qty RT - MAR",
"Running Stock",
"Stock Total",
"On order (BF required date)",
"J24 Quantity"})
in
#"Result",
type table[
#"Part" = text,
#"Forecast" =Int64.Type,
#"Forecast qty RT - MAR"=Int64.Type,
Running Stock=Int64.Type,
Stock Total=Int64.Type,
#"On order (BF required date)"=Int64.Type,
J24 Quantity=Int64.Type]
}}),
#"Expanded Tables" = Table.ExpandTableColumn(#"Grouped Rows", "Tables",
{"Forecast","Forecast qty RT - MAR", "Running Stock", "Stock Total", "On order (BF required date)", "J24 Quantity"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Tables",null,0,Replacer.ReplaceValue,{"On order (BF required date)"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",null,0,Replacer.ReplaceValue,{"Stock Total"}),
#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1",null,0,Replacer.ReplaceValue,{"J24 Quantity"})

in #"Replaced Value2"

 

 

PartForecastForecast qty RT - MARStock TotalOn order (BF required date)J24 Quantity

Screw11   
Screw33 2 
Screw87 20
Bolt77 00
Bolt1111920
Bolt1313920
Bolt1313920
Clamp66000
Clamp2224 0
Clamp883170
Clamp334074
Fire Damper101030030
Fire Damper55300 
Fire Damper33 3030
1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

hello, @Anonymous why don't you replace nulls with 0s across all your columns in the beginning (in between #"Changed Type" and #"Grouped Rows")? unless you don't do it on purpose of course...

= Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Forecast", "Forecast qty RT - MAR", "Stock Total", "On order (BF required date)", "J24 Quantity"})

 

View solution in original post

4 REPLIES 4
AlienSx
Super User
Super User

hello, @Anonymous why don't you replace nulls with 0s across all your columns in the beginning (in between #"Changed Type" and #"Grouped Rows")? unless you don't do it on purpose of course...

= Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Forecast", "Forecast qty RT - MAR", "Stock Total", "On order (BF required date)", "J24 Quantity"})

 

Anonymous
Not applicable

Hi thanks for the reply, yes I reliased that I needed to cahnge the null to 0 before the calculation.

Many thanks again.

Anonymous
Not applicable

As a newbie to Power Query I think i can see that my problem lies in this part of the code? After grouping and carrying out the formula then expanding any nulls that were put in before dont seem to stay in place during the list generate?? I have looked at List.sum and seen another article using ??0 but i cant get either of these to work.

Any help please as this has turned into another late!!! night

 

fq = t[#"Forecast qty RT - MAR"],
oo = t[#"On order (BF required date)"],

#"rtList" = List.Generate(
()=>[rt=t[Stock Total]{0} - fq{0} + oo{0}, idx=0],
each [idx] < List.Count(fq),
each [rt= if oo{[idx]} <> oo{[idx]+1}
then [rt] - fq{[idx]+1} + oo{[idx]+1}
else [rt] - fq{[idx]+1},
idx=[idx]+1],
each [rt]),

Anonymous
Not applicable

I seen a solution using List.Sum but wrapping with this hasnt worked? 

 

#"rtList" =List.Sum({ List.Generate(
()=>[rt=t[Stock Total]{0} - fq{0} + oo{0}, idx=0],
each [idx] < List.Count(fq),
each [rt= if oo{[idx]} <> oo{[idx]+1}
then [rt] - fq{[idx]+1} + oo{[idx]+1}
else [rt] - fq{[idx]+1},
idx=[idx]+1],
each [rt])}),

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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