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
LaurentZ
Helper I
Helper I

How to manage NaN or Infinity in PowerQuery (no Dax) ?

Hi,

Is there an easy way to manage NaN or Infinity ?

 

I tried to replace error, no impact.

I tried to replace "NaN" by 0, no impact (when it's working with Null).

In my formula I tried with "try a/b otherwise 0" but I still have the error.

 

I saw some test based on Number.IsNaN but it just tests NaN... what about Infinity or other errors...

 

The only way I found is to test Numerator and denominator (if Numerator=0 or Denominator = 0 then 0 else .... ), but maybe there is a better methodology like an equivalent to IFERROR in Excel? 

 

Thank you for your help.

 

(I'm using PowerQuery in Excel, so I don't have DAX measures & operators).

1 ACCEPTED SOLUTION

Thank you @edhans for your answer.

So there is no native function in powerquery to valuate those kind of error... that's sad.

Thanks for the article, I'll give a try later.

By waiting I keep my methodology tant consits in checking if Numerator & denominator are not 0 before doing a division... not the smartest but at least it works.

View solution in original post

8 REPLIES 8
CidcleyBarbosa
Advocate IV
Advocate IV

Hi everyone,
One way to do this is with List.Max(your calculation, 0).

@CidcleyBarbosa, don't forget curly brackets!

List.Max( { yourCalculation, 0 } )

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Diogo_Dalla
Frequent Visitor

I achieved the result by using

 

if (A / B) = Number.NegativeInfinity

then 0

else if (A  / B) = Number.PositiveInfinity

then 0

else (A  B)

joponlu
Frequent Visitor

You can convert numbers to text and evaluate them as a string with NaN or ∞

 

if Number.ToText([number]) = "∞"

or Number.ToText([number]) = "NaN"

 

then 0 else [number]

edhans
Super User
Super User

You will need to use the Number.IsNaN, Number.PositiveInfinity, Number.NegativeInfiinity, etc. The try/otherwise construct often doesn't work with these because they are not errors - even though Excel would trap them with IFERROR().

 

I recommend this excellent article on this issue which goes through all of these and more functions, and includes a very helpful function at the bottom to check all of these at once.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you @edhans for your answer.

So there is no native function in powerquery to valuate those kind of error... that's sad.

Thanks for the article, I'll give a try later.

By waiting I keep my methodology tant consits in checking if Numerator & denominator are not 0 before doing a division... not the smartest but at least it works.

Well @LaurentZ - it isn't technically an error, it is a valid result. But I do agree for most use cases NaN or any Infinity numbers aren't desired. The custom function I linked to will test for 4-5 results that are valid, but typically not desired, and remove them.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Greg_Deckler
Community Champion
Community Champion

@ImkeF @edhans


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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 Kudoed Authors