cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Applications
Helper IV
Helper IV

Trying to Build a Flow That Matches Names and Deducts Associated Values

Good morning. I'm trying to build an inventory flow that can automatically update stock quantities between two different SharePoint Lists, based on statuses and I need some help! What I have so far is this:

 

Applications_1-1655304889524.png

Applications_2-1655304934187.png

Applications_3-1655304986449.png

 

I'm not entirely sure if it's set up correctly, but it definitely doesn't run as intended, the last test I ran resulted in this error:

Applications_4-1655305061766.png

with the error stating, "Unable to process template language expressions in action 'Update_item' inputs at line '0' and column '0': 'The template language function 'sub' expects its first parameter to be an integer or a decimal number. The provided value is of type 'String'. Please see https://aka.ms/logicexpressions#sub for usage details.'."

 

I've tried a number of times to set and initialize the quantity columns in both lists as variables earlier in the flow as well, to no luck. What am I missing?

 

Also, in the flow I need to ensure that it only runs the quantities updates based on if the two columns between the lists (product name) match. I don't think my current flow has that anywhere, how would I achieve that?

 

Please bear in mind I'm very new to PowerAutomate flow building. 

 

Thank you kindly for your support!

12 REPLIES 12
Applications
Helper IV
Helper IV

Looking for some assistance on how to accomplish this - thanks!

eliotcole
Super User
Super User

@Applications I'm not sure that your issue here is wholly power automate, mate ... take a look at exactly how the number that you're using in that sub() expression is presented on a test run, to see what type of data it is.

 

More often than not, number columns in SharePoint are either presented as 'floating point' numbers (1.0 instead of 1), strings ("1") ... or both ("1.0"). You *can* create pure integer columns in SharePoint, but you can also translate them down in Power Automate.

 

For example, this:

@{sub(int(formatNumber(float(triggerOutputs()?['body/{VersionNumber}']), '0')), 1)}

First of all float() changes the Version number (which lists as "2.0") into a floating point number, then formatNumber() changes it into a single digit, then int() changes the string into a proper integer value.

I see, thanks! As far as putting that into an operation, would that be before the subtraction step? And which operation would you use? Or does this supplant the subtraction formula I have in currently? If so, where within that formula would I point to the two columns within each list? Thanks again!

Well, you'd need to show us your sub() expression. 😉


@Applications wrote:

I see, thanks! As far as putting that into an operation, would that be before the subtraction step? And which operation would you use? Or does this supplant the subtraction formula I have in currently? If so, where within that formula would I point to the two columns within each list? Thanks again!


 

Of course! Here is my current sub() expression:

 

Applications_0-1655734308314.png

 

Ah, OK, well your main issue here is that you aren't actually performing any maths, there.

Expression Is Badly Formatted

What your expression is actually trying to do is subtract the phrase "Quantity in Stock" from the phrase "Quantity" ... and I think that most maths programs will have some trouble with that, @Applications 😉.

 

( hope that it is clear that I'm not being rude, here, just playful! 🙂 )

 

You need to refer to actual columns, or literal values that you have defined somewhere else. This brings us neatly onto your second issue ...

 

Working On A Solution

Can you show me the value of the 'Quantity in Stock' column for a few items, @Applications ?

 

Perhaps just create a temporary flow (which you can delete afterwards) which runs a Get items on the list, and then for each one have a compose that shows that value.

 

Then just show screenshots of 2 or 3 of them.

 

 

This will assist in anything that you're doing ... I'm writing a 'generic' answer for you, but this will help you to be more prescriptive yourself in building the final solution.

Be Clearer With What You Need Here

Now that I'm looking at all of this, it's really unclear what one list does, and what the other list does ... then what the synching between the lists will hope to achieve.

 

If you can more clearly define that here, it will help someone give you a very specific solution to what you need here. To help yourself on this (in case it's unclear to yourself), try the next thing ...

 

You Need To Work Out Your Logic Here

Sit down with a pen and paper, and work out how the data in both lists relates to each other.

 

You might be able to do a lot of easy stuff without using flow, here, by referencing data between lists using 'Lookup' columns.

 

Clearly Referencing And Using Values

I *think* I know, but currently it's unclear which values 'Quantity in Stock' and 'Quantity' are referring to.

 

So, even though I can make educated guesses, this flow may need to be seen, used, or maintained, by other people, so you need to make some clearly defined data.

 

So, in order to both help yourself, and to help others, you need to define some information in this flow that makes sense in the context of what it is trying to do.

 

So, below I will make some assumptions, be sure to take what I am writing here GENERALLY. It is general advise on how to proceed, not *exact* things. Use it to create similar things on your end and don't view it as a literal, prescriptive, "do exactly what I say" solution.

 

Example

So, I am going to guess that you might need here:

  • The 'Quantity in Stock' in the previous version
  • The 'Quantity in Stock' in the new version
  • The difference between the two

So you should define these as variables.

 

I will assume that the value in that column is always a whole, integer, number (1, 2, 3), and is stored as such. If it is stored as "1.0" or as a string (text) value, then you will need to do more work on it (hence my previous comment in this thread).

 

So (assuming it is an integer) after your Get changes ... action create three Initialize variable actions for an integer values and name them as follows;

  1. previousStockQuantityVAR
  2. newStockQuantityVAR
  3. differenceStockQuantityVAR

Use the previous version value in the first one, the new value (from the trigger) in the second one, and in the third, you can use that sub() expression, except here it would be:

sub(
	variables('previousStockQuantityVAR'),
	variables('newStockQuantityVAR')
)

 

Now you can use the number that has been created in the differenceStockQuantityVAR anywhere in the flow, and it will be immediately obvious what it is.

 

Once you have got your head around referencing the values in certain parts of the flow, you can start to do more with it, and even do things without the variables (like you're currently trying to do).

 

However using the variables will help you see the logic more clearly whilst you're starting out. 🙂

@eliotcole 

 

Here is a screenshot of the SharePoint list that has the column values (Quantity in Stock)

Applications_0-1655812363830.png

 

And after building the test flow for the compose, here are those results:

1:

Applications_1-1655812712343.png

 

2:

Applications_2-1655812736534.png

 

3:

Applications_3-1655812776696.png

 

 

Be Clearer With What You Need Here
Now that I'm looking at all of this, it's really unclear what one list does, and what the other list does ... then what the synching between the lists will hope to achieve.
If you can more clearly define that here, it will help someone give you a very specific solution to what you need here. To help yourself on this (in case it's unclear to yourself), try the next thing

So what I'm trying to achieve is this:

  • List 1 has the full inventory of a shop (has the Quantity in Stock column)
  • A PowerApp was built to leverage that list so users can select from the inventory and order items
  • List 2 is the order information from the PowerApp (has the Quantity column)
  • I need a flow that does two things, based on statuses within List 2
    • First, identifies that an order has it's status changed to "Delivered"
    • Once the status change happens, it references the item name in List 2 to the item name in List 1, if it has the same name, move to next step which is deduction
    • Deducts the amount ordered in List 2 (Quantity) from the total inventory of the shop in List 1 (Quantity in Stock)
    • Changes the status from "Delivered" to "Posted" as a completion step

What I've done so far is start an automatic flow for when the status in List 2 changes to "Delivered", Get Items from List 1, and try to subtract those, but I understand from the post above, it's trying to subtract the phrases rather than the values (lol). I'm still new to all of this, but your guidance has been absolutely amazing - and with the step above with the compose and seeing that they are indeed being composed as values, gives me hope haha.

 

 

Clearly Referencing And Using Values
I *think* I know, but currently it's unclear which values 'Quantity in Stock' and 'Quantity' are referring to.
So, even though I can make educated guesses, this flow may need to be seen, used, or maintained, by other people, so you need to make some clearly defined data.
So, in order to both help yourself, and to help others, you need to define some information in this flow that makes sense in the context of what it is trying to do.
So, below I will make some assumptions, be sure to take what I am writing here GENERALLY. It is general advise on how to proceed, not *exact* things. Use it to create similar things on your end and don't view it as a literal, prescriptive, "do exactly what I say" solution.
Example
So, I am going to guess that you might need here:
  • The 'Quantity in Stock' in the previous version
  • The 'Quantity in Stock' in the new version
  • The difference between the two
So you should define these as variables.
I will assume that the value in that column is always a whole, integer, number (1, 2, 3), and is stored as such. If it is stored as "1.0" or as a string (text) value, then you will need to do more work on it (hence my previous comment in this thread).
So (assuming it is an integer) after your Get changes ... action create three Initialize variable actions for an integer values and name them as follows;
  1. previousStockQuantityVAR
  2. newStockQuantityVAR
  3. differenceStockQuantityVAR
Use the previous version value in the first one, the new value (from the trigger) in the second one, and in the third, you can use that sub() expression, except here it would be:
sub(
	variables('previousStockQuantityVAR'),
	variables('newStockQuantityVAR')
)
 
Now you can use the number that has been created in the differenceStockQuantityVAR anywhere in the flow, and it will be immediately obvious what it is.
Once you have got your head around referencing the values in certain parts of the flow, you can start to do more with it, and even do things without the variables (like you're currently trying to do).
However using the variables will help you see the logic more clearly whilst you're starting out.

 

When I try to initialize variable for the Get Items (List 1), it turns it into an Apply to Each control and then I get an error when trying to save it:

 

Applications_5-1655814130608.png

 

Here is what my overall flow looks like now though:

Applications_6-1655814199106.png

 

  • When an item is created or modified (New Order was posted in List 2)
  • Get Changes from List 2
  • Get Items (List 1)
  • Initialize Variable (Quantity ordered from List 2)
  • Initialize Variable (Quantity in Stock from List 1)
  • Condition to ensure status change was set to "Delivered"
  • Update Item (List 1, includes the subtraction formula)
    • Subtraction formula is: 
      sub(variables('QuantityInStockVAR'), variables('QuantityOrderedVAR'))
  • Update Item (List 2, changes Status to "Posted" once the subtraction has been complete in List 1)
  • Send an Email

 

Hope this helps with some clarification on what I'm trying to do vs. what I currently have - thank you! @eliotcole 

I've not got too much time to look fully at it now, but this will all really help, @Applications ... thanks! Whomever does help you with this ... or me ... will have a much easier time knowing this.

🙂👍

 

Pure instinctual reaction has me thinking you should have 2 flows with maybe two or three extra columns in list 1.

 

List 1 - New Columns

  • availablestock - Calculated Number column (no decimal places/thousands)
  • reservedstock - Number column (no decimal places/thousands)

Where availablestock will always be the formula:

=[stock]-[reservedstock]

So 'stock' will always indicate the total amount, but available stock will show what's available for other orders which might come in seconds afterwards.

 

Maybe some time in the future you can work out a system to identify individual order amounts in there.

 

Flow 1 - New Orders

  1. Trigger on List 2 on new item only

  2. Check that availablestock has enough to fulfill the order

  3. If it does, immediately add the amount requested to whatever value is currently in List 1's reservedstock
    This now means that any other orders can respond accordingly

  4. If it does not, respond to say that it's out of stock and they should resubmit and stop the flow

  5. After that conditional action do whatever is needed

 

Flow 2 - Delivered Orders

  1. Trigger on List 2 only when the status is equals to 'Delivered'

  2. Remove the ordered stock amount from reservedstock and stock in List 1
    Because it is now definitively gone

  3. Perform any other actions

 

End Result

Now you have a system that will ensure that stock levels are not only accurate, but also ensures that orders which are in progress won't impact other orders.

 

Obviously this is all around other processing here, and maybe other flows, but separating these two actions up like this will really ensure that it runs smoothly, I think.

 

As an example of potentially useful stuff that you could do which wouldn't need Flow at all ... I'd also recommend that you play with Lookup columns in List 1 which show which orders in List 2 are currently live. These lookup columns wouldn't have to be visible on all views, but they could be invaluable for understanding the data.

 

If I can I'll come back and try to do something for you. Otherwise, I'm sure someone else will have a pop ... good luck!

Understood! For the Flow 1 - New Orders portion, I don't think that's needed because within the PowerApp built it has some of that logic within the stock visualization process, so not needed within PowerAutomate. The other aspects I concur with and that's exactly what I'm looking for - thank you! I look forward to your (or anyone elses) support. Thank you!

@eliotcole 

 

Good morning! I tried modifying the flow based on the test we conducted yesterday, using Compose as a method to see if the columns were outputting integers, but it failed this morning. Is this an appropriate modification, or unnecessary? Thanks!

 

Modification:

Compose -> Quantity in Stock column in List 1

Initialize Variable -> Output of that

Compose -> Quantity column in List 2

Initialize Variable -> Output of that

 

Applications_0-1655904145097.png

 

Helpful resources

Announcements

Take a short Community User Survey | Help us make your experience better!

To ensure that we are providing the best possible experience for Community members, we want to hear from you!    We value your feedback! As part of our commitment to enhancing your experience, we invite you to participate in a brief 15-question survey. Your insights will help us improve our services and better serve the community.    👉Community User Survey    Thank you for being an essential part of our community!    Power Platform Engagement Team  

Tuesday Tip | How to Get Community Support

It's time for another Tuesday Tip, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.       This Week: All About Community Support Whether you're a seasoned community veteran or just getting started, you may need a bit of help from time to time! If you need to share feedback with the Community Engagement team about the community or are looking for ways we can assist you with user groups, events, or something else, Community Support is the place to start.   Community Support is part of every one of our communities, accessible to all our community members.   Within each community's Community Support page, you'll find three distinct areas, each with a different focus to help you when you need support from us most. Power Apps: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pa_community_support Power Automate: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpa_community_support Power Pages: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpp_community_support Copilot Studio: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pva_community-support   Community Support Form If you need more assistance, you can reach out to the Community Team via the Community support form. Choose the type of support you require and fill in the form accordingly. We will respond to you promptly.    Thank you for being an active part of our community. Your contributions make a difference!   Best Regards, The Community Management Team

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!    

Calling all User Group Leaders and Super Users! Mark Your Calendars for the next Community Ambassador Call on May 9th!

This month's Community Ambassador call is on May 9th at 9a & 3p PDT. Please keep an eye out in your private messages and Teams channels for your invitation. There are lots of exciting updates coming to the Community, and we have some exclusive opportunities to share with you! As always, we'll also review regular updates for User Groups, Super Users, and share general information about what's going on in the Community.     Be sure to register & we hope to see all of you there!

April 2024 Community Newsletter

We're pleased to share the April Community Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members.   If you're new to the Community, please make sure to follow the latest News & Announcements and check out the Community on LinkedIn as well! It's the best way to stay up-to-date with all the news from across Microsoft Power Platform and beyond.    COMMUNITY HIGHLIGHTS   Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, kudos, and providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, follow these awesome community members to see what they do!   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzDeenujialexander2523ragavanrajanLaurensMManishSolankiMattJimisonLucas001AmikcapuanodanilostephenrobertOliverRodriguestimlAndrewJManikandanSFubarmmbr1606VishnuReddy1997theMacResolutionsVishalJhaveriVictorIvanidzejsrandhawahagrua33ikExpiscornovusFGuerrero1PowerAddictgulshankhuranaANBExpiscornovusprathyooSpongYeNived_Nambiardeeksha15795apangelesGochixgrantjenkinsvasu24Mfon   LATEST NEWS   Business Applications Launch Event - On Demand In case you missed the Business Applications Launch Event, you can now catch up on all the announcements and watch the entire event on-demand inside Charles Lamanna's latest cloud blog.   This is your one stop shop for all the latest Copilot features across Power Platform and #Dynamics365, including first-hand looks at how companies such as Lenovo, Sonepar, Ford Motor Company, Omnicom and more are using these new capabilities in transformative ways. Click the image below to watch today!   Power Platform Community Conference 2024 is here! It's time to look forward to the next installment of the Power Platform Community Conference, which takes place this year on 18-20th September 2024 at the MGM Grand in Las Vegas!   Come and be inspired by Microsoft senior thought leaders and the engineers behind the #PowerPlatform, with Charles Lamanna, Sangya Singh, Ryan Cunningham, Kim Manis, Nirav Shah, Omar Aftab and Leon Welicki already confirmed to speak. You'll also be able to learn from industry experts and Microsoft MVPs who are dedicated to bridging the gap between humanity and technology. These include the likes of Lisa Crosbie, Victor Dantas, Kristine Kolodziejski, David Yack, Daniel Christian, Miguel Félix, and Mats Necker, with many more to be announced over the coming weeks.   Click here to watch our brand-new sizzle reel for #PPCC24 or click the image below to find out more about registration. See you in Vegas!       Power Up Program Announces New Video-Based Learning Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram. These include a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the image below to find out more!   UPCOMING EVENTS Microsoft Build - Seattle and Online - 21-23rd May 2024 Taking place on 21-23rd May 2024 both online and in Seattle, this is the perfect event to learn more about low code development, creating copilots, cloud platforms, and so much more to help you unleash the power of AI.   There's a serious wealth of talent speaking across the three days, including the likes of Satya Nadella, Amanda K. Silver, Scott Guthrie, Sarah Bird, Charles Lamanna, Miti J., Kevin Scott, Asha Sharma, Rajesh Jha, Arun Ulag, Clay Wesener, and many more.   And don't worry if you can't make it to Seattle, the event will be online and totally free to join. Click the image below to register for #MSBuild today!   European Collab Summit - Germany - 14-16th May 2024 The clock is counting down to the amazing European Collaboration Summit, which takes place in Germany May 14-16, 2024. #CollabSummit2024 is designed to provide cutting-edge insights and best practices into Power Platform, Microsoft 365, Teams, Viva, and so much more. There's a whole host of experts speakers across the three-day event, including the likes of Vesa Juvonen, Laurie Pottmeyer, Dan Holme, Mark Kashman, Dona Sarkar, Gavin Barron, Emily Mancini, Martina Grom, Ahmad Najjar, Liz Sundet, Nikki Chapple, Sara Fennah, Seb Matthews, Tobias Martin, Zoe Wilson, Fabian Williams, and many more.   Click the image below to find out more about #ECS2024 and register today!     Microsoft 365 & Power Platform Conference - Seattle - 3-7th June If you're looking to turbo boost your Power Platform skills this year, why not take a look at everything TechCon365 has to offer at the Seattle Convention Center on June 3-7, 2024.   This amazing 3-day conference (with 2 optional days of workshops) offers over 130 sessions across multiple tracks, alongside 25 workshops presented by Power Platform, Microsoft 365, Microsoft Teams, Viva, Azure, Copilot and AI experts. There's a great array of speakers, including the likes of Nirav Shah, Naomi Moneypenny, Jason Himmelstein, Heather Cook, Karuana Gatimu, Mark Kashman, Michelle Gilbert, Taiki Y., Kristi K., Nate Chamberlain, Julie Koesmarno, Daniel Glenn, Sarah Haase, Marc Windle, Amit Vasu, Joanne C Klein, Agnes Molnar, and many more.   Click the image below for more #Techcon365 intel and register today!     For more events, click the image below to visit the Microsoft Community Days website.      

Tuesday Tip | Update Your Community Profile Today!

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   We're excited to announce that updating your community profile has never been easier! Keeping your profile up to date is essential for staying connected and engaged with the community.   Check out the following Support Articles with these topics: Accessing Your Community ProfileRetrieving Your Profile URLUpdating Your Community Profile Time ZoneChanging Your Community Profile Picture (Avatar)Setting Your Date Display Preferences Click on your community link for more information: Power Apps, Power Automate, Power Pages, Copilot Studio   Thank you for being an active part of our community. Your contributions make a difference! Best Regards, The Community Management Team

Users online (3,906)