Forum Discussion

bdehning's avatar
bdehning
Post Prodigy
2 years ago
Solved

Custom Column Formula Help

I have the following formula for a custom column.  

 

It works except when Time Started or Time Injured is null and then my column returns an error

 

if([Time Started]>[Time Injured]) then [Time Injured]-[Time Started]+1 else [Time Injured]-[Time Started]

 

I would like to be to have the value be Unknown if possible?

  • bdehning 

    pls try this

    if [Time Started] is null or [Time Injured] is null then null else if [Time Started]>[Time Injured] then [Time Injured]-[Time Started]+1 else [Time Injured]-[Time Started]

     

10 Replies

  •  I know that would be best but my report is so big and complicated, its hard to split out just the page and table I need for a sample.   

    • ryan_mayu's avatar
      ryan_mayu
      Super User

      bdehning 

      not sure if this is what you want. We can't get text and number in one column

      Column = if(ISBLANK('Table (2)'[Time Started]) || isblank('Table (2)'[Time Injured]),999,if('Table (2)'[Time Started]>'Table (2)'[Time Injured],'Table (2)'[Time Injured]-'Table (2)'[Time Started]+1,'Table (2)'[Time Injured]-'Table (2)'[Time Started]))

       

      so i used 999 to replace the unknown

  •  Here is screen shot of Power Query   See my Time of Work Column which has the error?

  •  if([Time Started]>[Time Injured]) then [Time Injured]-[Time Started]+1 else [Time Injured]-[Time Started]  

     

    How do I add "if  time injured is null or time started is null then null" to what I already have?

     

    • ryan_mayu's avatar
      ryan_mayu
      Super User

      bdehning 

      pls try this

      if [Time Started] is null or [Time Injured] is null then null else if [Time Started]>[Time Injured] then [Time Injured]-[Time Started]+1 else [Time Injured]-[Time Started]