If calculated value column exceeds 24 hours

Brass Contributor

Hi!

 

I got this calculated column that shows values of "hh:mm:ss". But i've noticed that if its exceeds 24:00:00 it will restarts to ex. 01:00:00..

 

Is there anywat to make a validation or format the column so when it exceeds ex. 23:59:59 it will show the text "Over 24> hours" or something? Or is there any way to make it exceed 24:00:00?

 

This is my code in the calculated column:

 

{
  "$schema": "<a href="<a href="https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json" target="_blank">https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json</a>" target="_blank"><a href="https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json</a" target="_blank">https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json</a</a>>",
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField <= '02:00:00', 'sp-css-backgroundColor-successBackground50', if(@currentField >= '02:00:00', 'sp-css-backgroundColor-errorBackground50', '"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "=if(@currentField <= '02:00:00', 'CheckMark', if(@currentField >= '02:00:00', 'Warning', '"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

 

7 Replies

@288088 

 

You can try this in the txtcontent

=@currentField > 24 ? 'Over 24 hours' : @currentField

 

@O365Developer 

 

I'm kinda new to this, where in my code should I input this code?

 

Did like example below, doesnt work. Guess its all wrong

 

{
  "$schema": "<a href="https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json" target="_blank">https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json</a>",
  "elmType": "div",
  "attributes": {
    "class": "=if(@currentField <= '02:00:00', 'sp-css-backgroundColor-successBackground50', if(@currentField >= '02:00:00', 'sp-css-backgroundColor-errorBackground50', '"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "=if(@currentField <= '02:00:00', 'CheckMark', if(@currentField >= '02:00:00', 'Warning', '"
      }
    },
    {
      "elmType": "span",
      "txtContent": =@currentField > 24 ? 'Over 24 hours' : @currentField
    }
  ]
}

 

@288088 

Can you please try enclosing them in double quotes?

@O365Developer 

 

If I type like this I get error:

 {
      "elmType": "span",
      "txtContent": =@currentField > 24 ? "Over 24 hours" : @currentField
    }

@O365Developer 

 

can you pls try below and post me the error message if you get any

 

"txtContent": ="@currentField > 24 ? 'Over 24 hours' : @currentField"

@O365Developer 

 

It doesnt work...

 

Only shows like this:

 

I'm getting "Enter a valid JSON column formatting code" error.

 

"children": [
    {
      "elmType": "span",
      "txtContent": ="@currentField > 24 ? 'Over 24 hours' : @currentField",
      "attributes": {},
      "style": {
        "color": {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "@currentField",
                "00:00:00"

 

@288088 

 

Hi,

Thats a mistake in typo

 

"=if([$TimeField]==10,'Over 24','less than 24')" //assuming the TimeField is number or you can use @currentField='24:00:00'
 
Not sure,if you are aware about this
 you can try with this in your workspace.