0

I'm trying to create a new field that displays the last item select from another Multi selection Choice field. We currently use a choice for Portfolio Years which show as a string of values selected.

Multi Value lookup has a length property to work with but I want to just use the last value of the Choices selected. I don't see a properties or functions hyperlink in the learning center for JSON Formatting.

If I could do a simple split and use the last item in the array.

i.e "2022, 2023,2024" Show just 2024 in the new column.

1 Answer 1

0

You can use SharePoint JSON column formatting like below for your new column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=substring(join([$PortfolioYears],'||'),lastIndexOf(join([$PortfolioYears],'||'),'||')+2,indexOf(join([$PortfolioYears],'||') + '^', '^'))"
}

Where PortfolioYears is the name of your multiple selection choice column. You can get the exact internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

Output:

enter image description here


Update from comments:

In case if only one year is selected, below JSON should work:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(length([$PortfolioYears])==1,[$PortfolioYears],substring(join([$PortfolioYears],'||'),lastIndexOf(join([$PortfolioYears],'||'),'||')+2,indexOf(join([$PortfolioYears],'||') + '^', '^')))"
}

Output:

enter image description here

5
  • Thanks! That mostly worked. Some came back with 3 digits but a good starting point. I'll have to review the data to see why. It looks like the JSON pretty much follows most javascript functions?
    – Beruken
    Commented Oct 24, 2023 at 15:34
  • Can you edit your original question and screenshot of list view where results are coming back with 3 digits? Also, are you using the above JSON as is or you made any changes to it? Commented Oct 24, 2023 at 16:16
  • Ahh yes, Seems like it happens when only one choice is selected. How to add image?
    – Beruken
    Commented Oct 24, 2023 at 16:19
  • And yes, using your code verbatim
    – Beruken
    Commented Oct 24, 2023 at 16:30
  • Check the updated answer and JSON. Let me know if it works for you or if you face any issue. Commented Oct 25, 2023 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.