Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikster
Contributor III
Contributor III

Apply discount to the product with the lowest value.

Hi,

I've trying to do this in the script, managed to do it with an expression.

I want to find the lowest priced product per SubId and apply a discount (in this case 50%) and then sum the Totals.

FirstsortedValue should work i guess but I'm doing something wrong 🙂

 

This is the expression:

(Sum(FullPrice)
-
(Min({<flgNewOrder = {'1'}>} Aggr(FullPrice, [Product ID]))
*0.5))

 

SubIdProdIdFullPricePriceAfterDiscount
450623268268
450654226226
45061214572,5
    
    
 Total639566,5
Labels (3)
11 Replies
sunny_talwar

Problem is confusing, yes. But you know what is making this more difficult is the changing requirement. It seem you/your user are building onto the problem. It would be easier if we know the whole issue and try to resolve it instead of breaking it down.

Anyways, try this

Table:
LOAD SubId, 
     ProdId, 
     Fullprice as FullPrice, 
     DiscountPrice, 
     FinalPrice
FROM
[C:\Users\talwars\Downloads\DiscountProd.xlsx]
(ooxml, embedded labels, table is Blad1);

FinalTable:
LOAD *,
	 If(SubId = Previous(SubId), RangeSum(Peek('CountProdId'), 1), 1) as CountProdId,
	 If(If(SubId = Previous(SubId), RangeSum(Peek('CountProdId'), 1), 1) <= 2, DiscountPrice, FullPrice/2) as PriceAfterDiscount
Resident Table
Order By SubId, DiscountPrice desc;

DROP Table Table;
qlikster
Contributor III
Contributor III
Author

Hi Sunny,

after business has decided how to apply the new business rules I was able to solve the problem with a couple of modifications to your example.

It was a huge help so thanks for that!

 

I've accepted your reply as the solution.