Search This Blog

Tuesday, November 8, 2016

Qlikview , Aggr function the most powerful data grouping tactic

ตัวอย่างการใช้งาน
=AGGR(Count(DISTINCT
{<FactAll.FactType={"TX"}  >}
Product.ProductGroup ) , CustomerUID)


ตัวอย่างนี้เป็นการทำ Aggregate เพื่อให้ได้จำนวนออกมา โดยการนับ Product ที่ลูกค้า 1 คนซื้อ
เช่น Peter ซื้อ Cola และ Beer  ค่า Aggr จะได้ค่าเป็น 2 ซึ่งก็คือหลักการทำ Basket analysis
เมื่อมีจำนวนลูกค้ามากมายค่า Aggr ที่ได้ออกมาก็อาจจะเป็นตั้งแต่ 1-N ค่า


และต่อมาเมื่อต้องการวิเคราะห์ว่าลูกค้านิยมซื้อสินค้าใดร่วมกัน ก็สามารถใช้ Function Aggr นี้ได้
=Aggr( Concat( DISTINCT {<FactAll.FactType={"TX"}>}  Product.ProductGroup  ,' + ') , CustomerUID)
ผลลัพธ์ที่ได้จะออกมาดังนี้
1 Cola
1 Beer
1 Candy
2 Beer + Candy
2 Beer + Cola
3 Cola + Candy
3 Beer + Candy + Cola


Remarks * : {<FactAll.FactType={"TX"}>}   = Set analysis ที่บอกว่าต้องมีข้อมูล factType = "TX" เท่านั้นถึงจะนำมาคำนวณ

----------- อีกตัวอย่างเรื่องการนับจำนวน ตามเงื่อนไขการ SUMM
Hi,
I'm creating a line chart with month, and count().
count ( distinct Customer_Code)
How can i do the distinct count with IF statement. says count distinct customer if they sales is more than certain amount?
I tried :

if (sum(sales) <> 0 , count ( distinct Customer_Code))
But it's not working. and SET can't do sum() within it. any other alternatives?
Thanks
Trent Jones
Correct Answerby Trent Jones on Apr 20, 2011 12:43 PM
I would go with:

count(distinct aggr(if(sum(Sales)>100000,CustomerId),CustomerId))



No comments:

Post a Comment