Search This Blog

Monday, November 14, 2016

Qlikview , Sum sale of top N customer of each month


Using RANK function to check ranking of summary

Case1: Display rank with customer name for each month
Dimension1 = FactAll.MTH_YEAR
Dimension2 = Rank (Calculated Dim)
Dimension3 = CustomerName (Calculated Dim)

Dim2 :Rank
=Aggr(rank(sum(FactAll.Fee)),FactAll.MTH_YEAR ,Account.CustomerName)

Dim3 :CustomerName
=IF(AGGR(RANK(SUM(FactAll.Fee)),FactAll.MTH_YEAR, Account.CustomerName)<= 100 , Account.CustomerName )

























Case2: Display only summary of top 100 customer fee
Dimension1 = FactAll.MTH_YEAR
Expression = SumFee

Measure Expression :
=SUM(
IF(Aggr(rank(sum(FactAll.Fee)),FactAll.MTH_YEAR ,Account.CustomerName)<=100,
Aggr( sum(FactAll.Fee) ,FactAll.MTH_YEAR ,Account.CustomerName))
)


Qlikview , Sum sale of top N customer of each month


Using RANK function to check ranking of summary

Case1: Display rank with customer name for each month
Dimension1 = FactAll.MTH_YEAR
Dimension2 = Rank (Calculated Dim)
Dimension3 = CustomerName (Calculated Dim)

Dim2 :Rank
=Aggr(rank(sum(FactAll.Fee)),FactAll.MTH_YEAR ,Account.CustomerName)

Dim3 :CustomerName
=IF(AGGR(RANK(SUM(FactAll.Fee)),FactAll.MTH_YEAR, Account.CustomerName)<= 100 , Account.CustomerName )






















About order , Just order by rank 



Case2: Display only summary of top 100 customer fee
Dimension1 = FactAll.MTH_YEAR
Expression = SumFee

Measure Expression :
=SUM(
IF(Aggr(rank(sum(FactAll.Fee)),FactAll.MTH_YEAR ,Account.CustomerName)<=100,
Aggr( sum(FactAll.Fee) ,FactAll.MTH_YEAR ,Account.CustomerName))
)


Saturday, November 12, 2016

Qlikview , Set analysis refer variable name / Filter with expression


='Y'&vMaxYear& ' : Total New Customer : ' &
NUM(SUM({<Dim_Month.Year={$(=vMaxYear) }>}NewCustomerCount) ,'#,##0')




ตัวอย่างการ Sum fee ของเดือนปัจจุบัน
SUM({<Calendar.MonthlyNum ={$(=DATE(NOW(),'YYYYMM'))}>} FactAll.Fee)



https://community.qlik.com/thread/80861

jagan mohan rao appala
Correct Answerby jagan mohan rao appala on Apr 29, 2013 4:43 AM
Hi,

Try this expression

vDateMin = MonthStart(AddMonths(Max(Date), -12))
vDateMax = MonthEnd(AddMonths(Max(Date), -12))

=Sum({<YearDimensionName=, MonthDimensionName=, QuarterDimensionName=,Date = {">=$(=vDateMin)<=$(=vDateMax)"}>}$(vSales))

Exclude the date filters like Year, Month or Quarter selections if there are any.  Also check whether the date formats are same in Variable and Dimension.

Hope this helps you.

Thursday, November 10, 2016

Qlikview , Ignore (Except) all sections but one!


=NUM(
COUNT({$<[$(=Concat({1<$Field-={'Team.TeamName','Customer.CustBrokerageFlag','Customer.CustWealthFlag','Customer.CustBTSFlag','Marketing.MktName','Customer.CustEmployeeFlag'}>} distinct $Field,']=,[')&']=')
,Customer.CustStatus={"Available"} > }  DISTINCT CustomerUID)
,'#,##0')




=COUNT(
{$<[$(=Concat({1<$Field-={'FactAll.YEAR'}>} distinct $Field,']=,[')&']=')
  >}
  DISTINCT Account.MGM_ReferGroupID)


FactAll.YEAR หมายความว่า Selection ที่เกิดกับฟิลด์นี้มีผล ก็คือ Exception ของการนับ

ส่วนตย.ด้านบนที่มี  ,Customer.CustStatus={"Available"} หมายถึงต้องการ Filter อย่างอื่นเพิ่ม

งงมาก Script นี้


มีอีกตัวอย่างที่ง่าย และน่าจะโอเค
https://community.qlik.com/thread/60630

sum({1<FieldToKeep=P(FieldToKeep)>}Fieldname)




************* ตัวอย่างนี้สุดยอด **************
การนับวันทำงานที่เหลือของปี หรือไม่ก็เวลาที่กำหนด

=IF(GetSelectedCount(Calendar.Year)=0 ,
COUNT(  
{$<[$(=Concat({1<$Field-={'Calendar.Year', 'Calendar.Month'}>} distinct $Field,']=,[')&']=') ,Calendar.WorkingDay={"Y"},Calendar.Year={$(=DATE(FLOOR(NOW()-1),'YYYY'))},Calendar.Date={">=$(=FLOOR(NOW()))"}  >} 
DISTINCT    Calendar.Date)
,
COUNT(  
{$<[$(=Concat({1<$Field-={'Calendar.Year', 'Calendar.Month'}>} distinct $Field,']=,[')&']=') ,Calendar.WorkingDay={"Y"} ,Calendar.Date={">=$(=FLOOR(NOW()))"} >} 
DISTINCT    Calendar.Date)


)




*************อันนี้ต่อ String Field เพื่อทำ Except บางอย่าง ************* 
ดูผลลัพธ์ใน Text แล้วคือ Field ทั้งหมดที่มี 
=Concat({1<$Field-={'Calendar.Year'}>} distinct $Field,']=,[')&']=' 


Wednesday, November 9, 2016

Qlikview , Dual (Chart) function , Multiple value on data point

Credit : https://community.qlikview.com/thread/166577

As a requirement , how to display value on data point in difference way.

Example you have bar chart contain sum of sale across month. Let's say you want Y axis to show the exactly of sale summary , But value on bar chart showing % of each month vs total.

Using DUAL : DUAL Function
DUAL(Text ,Number)

Example =
DUAL(
  NUM(SUM(Sales)/SUM( TOTAL Sales) ,'#,##0.00%'),
  SUM(Sales)
)


The another useful technic to formatting the axis
https://community.qlik.com/thread/97554
Summary : Create a dummy expression and then set invisibility and set the number format in number tab as you want. Incredible! Marvellous!

Qlikview , Round() Function , The amazing function from Qlik

As we know we usually us Round() function an particular script.
Our perception was Round is use to round only the decimal digit , But Qlikview is so difference!
Please read the manual.
Qlikview ROUND()

Qlikview , ValueLoop (Chart function)


Refer to :
https://help.qlik.com/en-US/qlikview/12.0/Subsystems/Client/Content/ChartFunctions/SyntheticDimensionFunctions/valueloop.htm

The great function for some advance technical.

Qlikview , Auto generate

Load Date($(vMinDate) + recno()) as Date autogenerate vMaxDate - vMinDate

Tuesday, November 8, 2016

Qlikview , Variables

แนะนำให้ใช้ Variable ในการทำงาน ซึ่งจะส่งผลดีในอนาคตเนื่องจากค่าบางอยางเราจะต้องเรียกใช้บ่อยๆ และเมื่อใช้บ่อยๆแล้ว หากมีการเปลี่ยนแปลงสูตรคำนวนก็ต้องตามแก้ไขทุกจุด แต่หากใช้ Variable แทนก็จะลดปัญหานี้ไปได้เยอะ

การสร้าง Variable (Design)
Document properties -->Variables tab -->New

ตัวอย่างที่1 MeasureType
ใน Dashboard บางครั้งต้องการแสดงค่า Fee บางครั้งต้องการแสดง Value (Trade) เราควรมี Option ให้เลือกได้ว่าจะดูด้วย Measure ไหนเราสามารถสร้างตัวแปรมารับและใช้ Object input-box เพื่อสร้าง Listbox ให้เลือกได้

vMeasureType มีค่าเท่ากับ Fee หรือ Value
vMeasureValue จะอ้างถึง Field Name ที่จะนำมาใช้งาน
** แนะนำให้ตั้งชื่อตัวแปรเริ่มต้นด้วย "v"

--- vMeasureValue calc---
IF(vMeasureType ='Fee' ,'Fact.Fee','Fact.Value')

และใน Chart ที่จะเรียกใช้งานว่าจะกระทำโดยใช้ Fee หรือ Value ปกติจะเขียนแบบนี้
SUM( Fact.Fee) หรือ SUM(Fact.Value)
แต่หากใช้ตัวแปรแล้วจะอ้างถึงได้อย่างไร
1 อ้างถึงในเชิงใช้ค่าที่ได้ตรงๆ  = vMeasureValue
2 อ้างถึงเพื่อให้เป็น Dimension = $(vMeasureValue)

เมื่อใช้ใน Sum expression จะเป็น SUM(  $(vMeasureValue) )
โดยถ้า vMeasureType  = Fee จะเป็น Sum(Fact.Fee) Else Sum(Fact.Value)


Qlikview , Set analysis

Syntax ของ Set Analysis คือ {< Set1,Set2,Set3,SetN>}
Set1 Syntax = DimensionName = {""} เช่น 
{<ProductGroup={"Cola","Beer"}>} และถ้าต้องการทำ Set analysis มากกว่า 1 dimension จะเป็น

{<ProductGroup={"Cola","Beer"} ,Region={"North","South"}   >}



ตัวอย่างการใช้งาน
SUM(
{<ProductGroup={"Cola","Beer"} ,Region={"North","South"}   >}
 Sales)
คือ Sum ยอดขายของสินค้า Cola และ Beer ในภาคเหนือและใต้

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



Qlikview , How to get current active sheet name

You can not get sheet name ? What we gonna do ??
ตามที่บอกว่าไม่สามารถ Get active sheet "name" ได้ แต่สามารถ Get active sheet ID ได้ โดยใช้ Function =SUBFIELD(GetActiveSheetId(),'\',-1)

และ Qlikview มีข้อห้ามในการ Naming SheetID โดยถ้ามี Space จะทำให้มีปัญหา
ดังนั้นหากตั้ง Sheet Name = "Active Customer" แล้วต้องเป็น "Active_Customer"
หากจะนำ Sheet name มาแสดงให้ใช้ Script ในการตัด Under score "_" ออกไป ตามตัวอย่าง

=REPLACE(SUBFIELD(GetActiveSheetId(),'\',-1),'_',' ')

Qlikview , Alternate state การเปรียบเทียบข้อมูลใน Qlikview

Alternate stage เป็น feature ที่น่าสนใจและสามารถตอบโจทย์การใช้งาน Qlikview เพื่อการเปรียบเทียบ
ตัวอย่างเช่น หากเราต้องการเปรียบเทียบ Sale performance ของทีม Marketing สองทีมโดยใช้การสร้าง Group ในส่วน Alternate stage  และ Refer Group name ในส่วนที่ต้องการ

Setting : Document property --> General tab -->Alternate stage -->Create new
Refer : Example in list box : -->List box properties-->General tab -->Alternate state
Refer in expression : SUM( {Group1} Sales)
   Group1 = Group name we've create in alternate stage



Qlikview , Dimensionality , Checking current dimension level

Dimensionality() 

Qlikview , Refer expression name/title in another expression

การอ้างถึง Expression name ภายใต้ Chart เพื่อใช้คำนวณใน Expression อื่นๆต่อไป
ตัวอย่าง

Expression 1 = "Sales"   Script =  SUM(Sales)
Expression 2 = "Active Mkt"   Script =  COUNT(DISTINCT MarketingID)
Expression 3 = "Revenue per Mkt" Script =

SUM(Sales) / COUNT(DISTINCT MarketingID)
ในกรณีนี้ Script ไม่ได้ยาวและซับซ้อน แต่หากมี Script ที่ซับซ้อนและยาวมากๆ
การที่จะต้องเขียน Script นั้นใหม่มีโอกาสที่จะผิดพลาดได้ง่าย เนื่องจากหากมีการแก้ไขสูตร
ก็จะต้องตามแก้ไขทั้งสองที่

ดังนั้นเราสามารถที่จะอ้างถึงชื่อ Expression ภายใน Chart ที่กำลังทำงานอยู่ได้ด้วย Syntax นี้

อ้างถึง Expression "Sale"    $(='[Sales]') , "Active Mkt"  $(='[Active Mkt]') 
ดังนั้นใน Expression 3 เราสามารถเขียนให้สั้นและง่ายได้ดังนี้
 $(='[Sales]')/ $(='[Active Mkt]') 


How to reference to calculated label name??

Example
Calculated :  'Y'&(Year(Today())-1)
Refer :   $(='[Y'&(Year(Today())-1)&']')