none
Calculations in Collection

    Question

  • Hi, I have a problem...

    My Gallery...

    Item          Cost          Amount(Slider)  Add Basket(toggle)

    Eggs          10             1,2,3                Yes/No

    Bacon        20             1,2,3                Yes/No

    I create a collection based on what is added to the basket but...I

    I want to add a discount of 10% if the Slider is 1, 20% if 2 etc.

    Is this possible?

    Thanks in advance.

    Saturday, August 30, 2014 9:43 AM

All replies

  • Hello,

    I believe the following should help you out.

    • Assuming you have a slider (Slider1 max set to 3) in each of the items in your gallery so you can set volumes per item.
    • Assuming you have labels in your gallery listprice, discount and newprice

    You can then set the text of your discount label to

    If(Slider1!Value=1,10%,If(Slider1!Value=2,20%,If(Slider1!Value=3,30%)))

    you can hide the label if you don't want the users to see it.

    your can then set the text of your newprice label to

    Value(listprice!Text)*(1-Value(discount!Text))

    You should also add the discount and newprice item to your collection allowing you to do things with the overall result.

    Hope this helps

    Regards
    StonyArc


    http://www.stonyarc.com http://www.xboxlivenation.com

    • Proposed as answer by StonyArcMVP Saturday, August 30, 2014 10:17 PM
    Saturday, August 30, 2014 10:17 PM
  • Hi StonyArc,

    That works well getting my discounts working so thank you. However, my Add to Basket Toggle will not let me add the discount or newprice to the collection.

    Collect(Collection1, {Discount: labelDiscount!Text}) adds a line to the collection with only the Discount, but I want to combine it with ThisItem

    i.e. end up with a collection of:

    Item          Amount      Cost       Discount       NewPrice

    Eggs          2               $10        20%             $8

    My source table has Item, Cost

    My Gallery has Item, Cost, Discount, NewPrice

    Thanks, Nathan

    Sunday, August 31, 2014 8:57 AM
  • Hello,

    I believe you need to look at the addcolumns function (other option would be context variable and increment).

    That will allow you to create what you need

    Your items for your gallery will then look like

    AddColumns(Collection1,"Discount",Value(discount!Text),"NewPrice",Value(listprice!Text)*(1-Value(discount!Text)))

    Please note that this not change the original table but add temp columns.

    If you want to look for making a total you can use the !AllItems outside the gallery.

    Hope this works for you

    Regards
    StonyArc


    http://www.stonyarc.com http://www.xboxlivenation.com


    • Edited by StonyArcMVP Sunday, August 31, 2014 6:18 PM
    • Proposed as answer by StonyArcMVP Sunday, August 31, 2014 6:19 PM
    Sunday, August 31, 2014 6:17 PM
  • Hi StonyArc,

    I eventually got it to work by moving my source from Excel to AMS which gave a unique id column, then...

    in the 'add to basket' toggle onCheck
    Collect(Collection1, ThisItem);UpdateIf(Collection1, id = ThisItem!id, {Price: Price*lblDiscount!Text})

    and

    in the 'add to basket' onUncheck
    Remove(Collection1, ThisItem);RemoveIf(Collection1, id = ThisItem!id)

    I'm sure your answer would have worked if I knew where to add the suggested command, but im a bit new at this (i.e. I have no clue what I am doing).

    Thanks very much for your help,

    Nathan

    Monday, September 01, 2014 7:12 AM
  • Hello Natan,

    If you want your data to be stored even if the user closes the app you can add behind your statement after a ;

    SaveData(Collection1,"Collection1File")

    To make sure it loads on the first screen or on your basket screen

    Clear(Collection1);LoadData(Collection1,"Collection1File")

    Regards
    StonyArc


    http://www.stonyarc.com http://www.xboxlivenation.com

    Monday, September 01, 2014 9:09 AM