cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
petewalburn
Frequent Visitor

Filter a Sharepoint list for a column starting with current year

Hi,

 

I have a Sharepoint list with a column which contains unique values which start with the current year and then a '-', followed by an integer starting at 1 and incrementing for each record. So, it is something like:

 

2022-0001

2022-0002

2022-0003

 

I want to have a function to return the next number for the current year.  

 

I have done this in PowerApps, but I need to have a function that can be called from different places.

In PowerApps, I did this:

 

Set(numberList,Sort('datasource','Number column', Descending));
Set(varIDno,LookUp(numberList,Mid('Number column',1,4)=Text(Today(),"yyyy")).'Number column');
Set(varNo,Value(Right(varIDno,4))+1);
Set(varNewNo,Text(Today(),"yyyy") & "-" & If(IsBlank(varIDno), "0001", Text(varNo,"0000")));

 

I thought that I would be able to create a function in Power Automate to return the next number for the current year, but can't figure out how to do this.

 

Maybe it is OK to keep it within the PowerApps application, but I need to have it in a function that can be called from different places.

 

I'm fairly new to PowerApps, so any help is much appreciated.

 

Pete

 

3 REPLIES 3
WarrenBelz
Super User
Super User

Hi @petewalburn ,

Firstly this is free-typed and you will need to change any of your values not correct here (DataSource, 'Number column'), but should give you an idea what is required

 

With(
   {
      wYear: 
      Text(Year(Today()),"yyyy")
   },
   With(
      {
         wLastNo:
         LookUp(
            Sort(
               Filter(
                  DataSource,
                  StartsWith(
                     'Number column',
                     wYear
                  )
               ),
               'Number column',
               Descending
            )
         ).'Number column'
      },
      Set(
         varNewNo,
         wYear & "-" & 
         Text(
            Value(
               Last(
                  Split(
                     wLastNo,
                     "-"
                  )
               ).Result
            ) + 1,
            "000"
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

WarrenBelz, thanks for trying to help.

 

I've used your code to try to get the new number, but I get errors which I cannot figure out.

 

I've used:

With(
{

  wYear: Text(Year(Today()),"yyyy")

},
With(
{
  wLastNo:
  LookUp(
    Sort(
      Filter('datasource', StartsWith('Number column',wYear)),'Number column',Descending)
    ).'Number column'
},
Set(varNewNo,wYear & "-" & Text(Value(Last(Split(wLastNo,"-")).Result)+1,"000"))
)

 

The code that I was using initially does give me the required value, but I really wanted to be able to add this as a function that can be called from many different areas (Onselect methods of a few button controls).

 

Also, I believe that the Filter method is limited on the size of the data source.  I thought that if I did this in a Power Automate data flow, I could get it to work on larger data sources and could call it form multiple places.

 

Pete
)

 

One error is:

"Invalid number of arguments: received 1, expected 2-3" 

I think this is on the Filter function

Also,

"Invalid use of '.'

this is on the ).'Number column'  in the Sort function

 

@petewalburn ,

You were missing a closing bracket on yours, it looks OK visually, but without actual data, it is a bit hard to test.

With(
   {
      wYear: 
      Text(
         Year(Today()),
		 "yyyy"
      )
   },
   With(
      {
         wLastNo:
         LookUp(
            Sort(
               Filter(
                  'datasource', 
                  StartsWith(
                     'Number column',
                     wYear
                  )
               ),
               'Number column',
               Descending
            )
         ).'Number column'
      },
      Set(
         varNewNo,
         wYear & "-" & 
         Text(
            Value(
               Last(
                  Split(
                     wLastNo,
                     "-"
                  )
               ).Result
            ) + 1,
            "000"
         )
      )
   )
)

I am not a Power Automate guru (far from it), so it may be better to post on that forum.

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,694)