cancel
Showing results for
Did you mean:
Helper III

## calculate discount code

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)),
)

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 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

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!

10 REPLIES 10
Helper III

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 🙂

Super User

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)),
)``````

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!

Helper III

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.

Super User

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

Helper III

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 🙂

Helper III

@LaurensM  any suggestions on this? thanks again 🙂

Super User

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!

Helper III

@LaurensM  Thanks for explaining it, amazaing

Helper III

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

Announcements

#### April 4th Copilot Studio Coffee Chat | Recording Now Available

Did you miss the Copilot Studio Coffee Chat on April 4th? This exciting and informative session with Dewain Robinson and Gary Pretty is now available to watch in our Community Galleries!   This AMA discussed how Copilot Studio is using the conversational AI-powered technology to aid and assist in the building of chatbots. Dewain is a Principal Program Manager with Copilot Studio. Gary is a Principal Program Manager with Copilot Studio and Conversational AI. Both of them had great insights to share with the community and answered some very interesting questions!     As part of our ongoing Coffee Chat AMA series, this engaging session gives the Community the unique opportunity to learn more about the latest Power Platform Copilot plans, where we’ll focus, and gain insight into upcoming features. We’re looking forward to hearing from the community at the next AMA, so hang on to your questions!   Watch the recording in the Gallery today: April 4th Copilot Studio Coffee Chat AMA