Forum Discussion
Jonas_Daragas
Feb 03, 2023Copper Contributor
Generate autotext + number in column in SP list
Hi everyone,
I've been looking everywhere for a solution to my problem.
I've made a list that has all sorts of machines. Our intern ID is specified by a set of letters like: BTARM(+number of the machine). I want to auto generate this everytime a new item gets listed. The formule I found was:
=IF(ISBLANK(InternID);"BTARM1";TEXT(MAX(InternID)+1, "BTARM0"))
It keeps giving my syntaxis errors. So I'm still unsure what could be wrong in this code). The list already contains 76 rows but I doubt it has something to do with that. It's probably something I'm missing in the formula like (; instead of ,) or ( [ instead ( ). Anyone that could help me out? I've been talking with ChatGPT for 3 days straight
If you are looking for the MAX([InternID]) to return the maximum value of InternID in the list, that is not possible. The formula can only use other columns in the same item(row).
If you are just trying to concatenate the custom text with the InternID from the same item, try the following formula:
=IF(ISBLANK([InternID]),"BTARM1","BTARM0"&[InternID])
I'm not sure that is exactly what you are looking for, but hopefully will get you close enough to adjust for yourself.
Here are some additional references
- https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/bb862071(v=office.14)
- https://support.microsoft.com/en-us/office/examples-of-common-formulas-in-lists-d81f5f21-2b4e-45ce-b170-bf7ebf6988b3
- https://www.spguides.com/sharepoint-calculated-column/
Good luck!Don
If my answer helps solve or resolve your issue, please consider clicking Mark as Best Response & Like. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it a Like.
- RobElliottSilver Contributor
Jonas_Daragas you can't do this SharePoint; a calculated column can't loop through all the items in the InternID column to get the max value unlike Excel, it only works across the current item. But you can build a simple flow in Power Automate to achieve this. Create it from blank, there won't be a template for this.
1. The trigger is the SharePoint when a new item is created. Select your site and your list. Next add an initialize variable action, give it a name and make the type Float. Leave the value empty.
2. Next we want to get the maximum value of the InternID column. So add a SharePoint get items action. Select your site and list. That will add your columns to the action. When it has done so click the Show advanced options at the bottom of the flow. In the filter query field type InternID ne '' and inside the single quotes, from the dynamic content box click the Expression tab and type null then click OK. Click in the Order By field and type InternID desc and in the Top Count field type 1
Even though we are only bringing back 1 item add an apply to each action and select value from the dynamic content box.
Next, add a Set variable action, select the variable name and in the value field select InternID from the get items section of the dynamic content box.
Next, add an increment variable action, select the variable and in the value field type 1.
Finally, add a SharePoint update item action. Select the Site and List, and from the dynamic content box select ID and Title from the create item section of the dynamic content box. Click in the InternID field and select the variable.
In this example the previous maximum value was 76 but after adding the Mauritius item the flow triggered and gave it the InternID of 77.
You'd never have got that solution with ChatGPT!
Rob
Los Gallardos
Microsoft Power Automate Community Super User- Jonas_DaragasCopper Contributor
Hey RobElliott
Thanks already for getting me started. I keep getting an error with the action Get Items (see screenshot). It shows that the expression 'InternID ne' is not valid. Any toughts on this?
Also it is unclear to me will this generate the letters BTARM in this Power Automate? Like BTARM1, BTARM2, BTARM3 etc.
Thank you
- RobElliottSilver ContributorCheck the filter query has a single both before and after the null expression, from your screenshot there on'y appears to be 1 single quote.
I'd forgotten you wanted the letters as well,. This flow doesn't do that, it just increments the maximum value. I'll re-read your post and give you a solution as soon as possible.