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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Power Query - how to handle Divide by 0?

Hi,

I have some Power Query code that is returning either NaN or Infinity values. I believe this to be a Divide by 0 issue.

 

How would I handle a divide by 0 in the below line of Power Query code:
#"Grouped Rows" = Table.Group( #"Filtered Rows", {"Division"}, {{"All", each _, type table}}),
#"Added Custom" = Table.AddColumn( #"Grouped Rows", "DEValue",    each [All]{[Grouping_Level="Gross Profit"]}[DEValue]     / [All]{[Grouping_Level="Sales"]}[DEValue]),
#"Added Custom1" = Table.AddColumn( #"Added Custom", "DETarget",  each [All]{[Grouping_Level="Gross Profit"]}[DETarget]   / [All]{[Grouping_Level="Sales"]}[DETarget]),
#"Added Custom2" = Table.AddColumn( #"Added Custom1", "MTDValue",  each [All]{[Grouping_Level="Gross Profit"]}[MTDValue]  / [All]{[Grouping_Level="Sales"]}[MTDValue]),
#"Added Custom3" = Table.AddColumn( #"Added Custom2", "MTDTarget", each [All]{[Grouping_Level="Gross Profit"]}[MTDTarget] / [All]{[Grouping_Level="Sales"]}[MTDTarget]),
#"Added Custom4" = Table.AddColumn( #"Added Custom3", "Grouping_Level", each "**bleep**M"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom4", {"All"}),

 

Thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I've worked it out:

#"Grouped Rows" = Table.Group( #"Filtered Rows", {"Division"}, {{"All", each _, type table}}),
#"Added Custom" = Table.AddColumn( #"Grouped Rows", "DEValue",     each if [All]{[Grouping_Level="Sales"]}[DEValue]   = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[DEValue]    / [All]{[Grouping_Level="Sales"]}[DEValue]),
#"Added Custom1" = Table.AddColumn( #"Added Custom", "DETarget",   each if [All]{[Grouping_Level="Sales"]}[DETarget]  = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[DETarget]   / [All]{[Grouping_Level="Sales"]}[DETarget]),
#"Added Custom2" = Table.AddColumn( #"Added Custom1", "MTDValue",  each if [All]{[Grouping_Level="Sales"]}[MTDValue]  = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[MTDValue]   / [All]{[Grouping_Level="Sales"]}[MTDValue]),
#"Added Custom3" = Table.AddColumn( #"Added Custom2", "MTDTarget", each if [All]{[Grouping_Level="Sales"]}[MTDTarget] = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[MTDTarget]  / [All]{[Grouping_Level="Sales"]}[MTDTarget]),
#"Added Custom4" = Table.AddColumn( #"Added Custom3", "Grouping_Level", each "**bleep**M"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom4", {"All"}),

 

Just needed a little trial and error in the positioning of the added.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

I've worked it out:

#"Grouped Rows" = Table.Group( #"Filtered Rows", {"Division"}, {{"All", each _, type table}}),
#"Added Custom" = Table.AddColumn( #"Grouped Rows", "DEValue",     each if [All]{[Grouping_Level="Sales"]}[DEValue]   = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[DEValue]    / [All]{[Grouping_Level="Sales"]}[DEValue]),
#"Added Custom1" = Table.AddColumn( #"Added Custom", "DETarget",   each if [All]{[Grouping_Level="Sales"]}[DETarget]  = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[DETarget]   / [All]{[Grouping_Level="Sales"]}[DETarget]),
#"Added Custom2" = Table.AddColumn( #"Added Custom1", "MTDValue",  each if [All]{[Grouping_Level="Sales"]}[MTDValue]  = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[MTDValue]   / [All]{[Grouping_Level="Sales"]}[MTDValue]),
#"Added Custom3" = Table.AddColumn( #"Added Custom2", "MTDTarget", each if [All]{[Grouping_Level="Sales"]}[MTDTarget] = 0 then 0 else [All]{[Grouping_Level="Gross Profit"]}[MTDTarget]  / [All]{[Grouping_Level="Sales"]}[MTDTarget]),
#"Added Custom4" = Table.AddColumn( #"Added Custom3", "Grouping_Level", each "**bleep**M"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom4", {"All"}),

 

Just needed a little trial and error in the positioning of the added.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors