Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

IF OR function for calculation to remove error that returns

Hi everyone,

 

I'm attempting to write an if or formula that will calculate the percentage of payment of revenue. Essentially a collection rate. For all that have numbers greater than 0 in both revenue and payment columns, it's working as expected. When there is a zero in either the revenue column or payment column, I am getting a NaN error. 

 

I want to essentially write a formula that says ignore the 0 in revenue, or return it as 1 so it doesn't through off collection rate, and to also return 0 anytime payment equals 0, while revenue equals anything other than 0.  I've written so many variations an keep running into error after error as I correct Token Literal, Token Else, Token Right Paren. 

 

I'm stumped, can anyone help me? Below is where I was closest, but have a Token Else expected error. The error highlights the last e in else.

 

 

if( OR([Insurance Payment Grouping.Insurance Payment]=0,[Insurance Revenue]=0)) then 0) else ([Insurance Payment Grouping.Insurance Payment]/[Insurance Revenue]

10 Replies

  • Anonymous ,

    Try this instead, assuming this is a calculated column:

    DIVIDE([Insurance Payment Grouping.Insurance Payment], [Insurance Revenue], 0)

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      The syntax works, but I get the following error:   Expression.Error: The name 'DIVIDE' wasn't recognized. Make sure it's spelled correctly. Also tried it in lower case, same expression error.

      • hnguy71's avatar
        hnguy71
        Super User

        Anonymous , you'd need to give it a column name:

         

        NewColumn = DIVIDE([Insurance Payment Grouping.Insurance Payment], [Insurance Revenue], 0)
  • Hi,

    Try this measure

    =coalesce(divide([Insurance Payment Grouping.Insurance Payment],[Insurance Revenue]),0)

    I assume that [Insurance Payment Grouping.Insurance Payment] and [Insurance Revenue] are measures. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Ashish, this is a PowerBI Custom Column calculation. It's giving me the Expression.Error when I try to execute this formula. Any thoughts on how to fix or update for PowerBI?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        From the error, i guess it is a Query Editor error.  In the Query Editor, try this

        =try [Insurance Payment Grouping.Insurance Payment]/[Insurance Revenue] else null

        If this does not work, then share the link from where i can download your PBI file.