web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / calculate discount code
Power Apps
Unanswered

calculate discount code

(0) ShareShare
ReportReport
Posted on by 104

hiya, 

 

I have a online store where the gallery which is coming from the dataverse table products. i also have another table called customer discounts and they can use a promo code to check if it is correct, to update the total amount. 

 

I'm still learning about power apps, ive written a IF statement to check the code is correct 

If(
IsEmpty(Filter('Promotion Codes', PromoCodeID = TextInput1.Text)),
Notify("Invalid discount code", NotificationType.Error),
Notify("Valid discount code", NotificationType.Success)
)

 

However there is a field in the discount table which is amount discounted i.e £10. any suggestions on how this number can subtract the total amount?

 

thanks 🙂

Categories:
I have the same question (0)
  • daniellemaree85 Profile Picture
    104 on at

    hiya, 

     

    I have a online store where the gallery which is coming from the dataverse table products. i also have another table called customer discounts and they can use a promo code to check if it is correct, to update the total amount. 

     

    I'm still learning about power apps, how can you check the code input against the customer discount table that code is valid? 

     

    thanks 🙂

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @daniellemaree85😊

     

    Since you are looking for a single record to match your condition you can use a LookUp instead to check whether the code is available:

    If(
     IsBlank(LookUp('Promotion Codes', PromoCodeID = TextInput1.Text)),
     Notify("Invalid discount code", NotificationType.Error),
     Notify("Valid discount code", NotificationType.Success)
    )

     

    To apply the discount you will have to add additional code to your current total cost calculation:

    <Your code to calculate total cost> - LookUp('Promotion Codes', PromoCodeID = TextInput1.Text, DiscountColumn)

    If no valid code is found, no discount will be applied to your total cost.

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • daniellemaree85 Profile Picture
    104 on at

    thanks @LaurensM  for your suggestion

     

    would you have an example how to calculate the difference? i have used a decimal column in dataverse, im still  bit a newbie to all of this.  

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @daniellemaree85,

     

    No worries! Would it be possible to provide your current logic that calculates the total cost?

  • daniellemaree85 Profile Picture
    104 on at

    hiya @LaurensM 

     

    that would be super fab! 

     

    the total amount is from a previous collection in a gallery

     

    With( {ST:Sum(colShoppingCart, SUBTOTAL)}, "Item Total:" & Text(ST, " £#,##0.00"))

     

    the collection is colshopping car where its calculating the qty x the list price.

     

    (colShoppingCart, {SUBTOTAL: (SliderQty.Value * ThisItem.'Product List Price')})})

     

    i hope that helps 🙂

  • daniellemaree85 Profile Picture
    104 on at

    @LaurensM  any suggestions on this? thanks again 🙂

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @daniellemaree85😊

     

    Thanks for the reminder, I seem to have missed your previous comment.

     

    You will have to subtract the Sum() output with the LookUp function that is returning the possible discount value:

    With( 
     {
     //Adjust DiscountColumn to the correct column name
     wTotal: Sum(colShoppingCart, SUBTOTAL) - LookUp('Promotion Codes', PromoCodeID = TextInput1.Text, DiscountColumn)
     }, 
     "Item Total:" & Text(wTotal, " £#,##0.00")
    )

    In the code above, we expect discount to be a numeric column.

     

    I hope this helps!

  • daniellemaree85 Profile Picture
    104 on at

    @LaurensM  Thanks for explaining it, amazaing

  • daniellemaree85 Profile Picture
    104 on at

    @LaurensM  if i want to set the new number to a variable how could i do that?

  • LaurensM Profile Picture
    12,516 Moderator on at

    @daniellemaree85 

     

    You can save the value to a variable during a certain action (e.g. OnVisible of a screen, press of a button...).

    Set(
     gblShoppingCartTotal,
     Sum(colShoppingCart, SUBTOTAL) - LookUp('Promotion Codes', PromoCodeID = TextInput1.Text, DiscountColumn)
    )

     

    Should they have to validate the code via a button first, then you can use the code above to store the new value after the button is pressed & discount code is validated. To avoid having duplicate logic, you could in this case reduce the code in the label displaying the total value to:

    "Item Total:" & Text(gblShoppingCartTotal, " £#,##0.00")

     

    I hope this helps!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard