วันอังคารที่ 28 พฤษภาคม พ.ศ. 2556

How to clear index (aggregation file) from you Cube or partition

Using  ProcessClearIndexes 
ปกติแล้วใน UI (SSMS) จะไม่มี Option นี้ให้เลือกใช้
แต่สามารถใช้ได้โดยการใช้ Script แทน


Credit by :
http://searchsqlserver.techtarget.com/tip/Recommended-practices-for-SQL-Server-Analysis-Services-aggregations


วันอังคารที่ 9 ตุลาคม พ.ศ. 2555

Sql server , Summary accumulate , running total



I prefer  the second and the third sulution

Solution 2: The "Celko" Solution

(NoIndex = 25 secs, Index = 20 secs)
SELECT DayCount,
       Sales,
       Sales+COALESCE((SELECT SUM(Sales) 
                      FROM Sales b 
                      WHERE b.DayCount < a.DayCount),0)
                         AS RunningTotal
FROM Sales a
ORDER BY DayCount



Solution 3: The "Guru's Guide" Solution

(NoIndex = 38 secs, Index = 17 secs)
SELECT a.DayCount,
       a.Sales,
       SUM(b.Sales)
FROM Sales a
CROSS JOIN Sales b
WHERE (b.DayCount <= a.DayCount) AS RunningTotal
GROUP BY a.DayCount,a.Sales
ORDER BY a.DayCount,a.Sales


วันศุกร์ที่ 28 กันยายน พ.ศ. 2555

MDX Dynamic Hierarchy 1


ตัวอย่างการทำ Dynamic Hierarchy กับ Calculate member
LEVELS ใช้ Function นี้ในการ Convert string เป็น Hierarchy LEVEL ได้
MEMBERS  ใช้ Function นี้ในการ Convert string เป็น Member (CurrentMember) ได้ด้วย

With member [Measures].[HRC] as
"[Dim_Date].[HRC_YQMD]"

MEMBER [Measures].[AccmCash] as
    Aggregate(
          PERIODSTODATE(
            LEVELS([Measures].[HRC]+".[Year]"),-- CONVERT String to LEVEL
            MEMBERS([Measures].[HRC]+".CURRENTMEMBER") -- CONVERT String to MEMBER
          ),[Measures].[Cash])


SELECT {[Measures].[Cash],[Measures].[AccmCash]} ON 0,
NON EMPTY
[Dim_Date].[Hrc_YQMD].[Date].MEMBERS ON 1
FROM (SELECT [Dim_Date].[Month].&[201201] ON 0 FROM [Cube_Txns])

RESULT
Date                  CASH            ACCMCASH

20120101 44,176,675 44,176,675
20120102 46,656,659 90,833,334
20120103 43,954,618 134,787,952
20120104 46,481,631 181,269,583
20120105 45,993,021 227,262,603
20120106 43,674,555 270,937,158
20120107 40,730,331 311,667,489
20120108 37,520,953 349,188,442
20120109 41,457,006 390,645,448
20120110 41,601,764 432,247,212




วันพุธที่ 26 กันยายน พ.ศ. 2555

Excel & OLAP Pivot table


การสร้าง Pivot table จาก OLAP ใน MS Excel

1. Connection ที่สร้างใหม่จะเป็นไฟล์อยู่ในเครื่อง Computer นั้นๆ
2. Connection ที่สร้างไว้แล้วสามารถ Reuse ได้
3. ใน Excel work book สามารถอ้างถึง Connection ในเครื่อง Computer ที่สร้างไว้ได้
  3.1 โดย default , Excel จะ Copy connection string จาก Connection file ในเครื่อง computer มาไว้ใน Work Book
  3.2 เราสามารถเลือก Option ให้ Excel link connection จาก Connection file ในเครื่อง Computer ได้
  3.3 โดย default , Excel จะไม่ save password ไว้ใน Connection string ที่ Copy มาไว้ใน Workbook ต้องคลิ๊กเลือก Save passord เอง

4. Connection ใน Excel work book สามารถถูกอ้างถึงจาก Pivot table หลาย pivot ได้
   4.1 การ Refresh pivot table ใดๆ จะทำการ Refresh Connection ที่ pivot table นั้น Refer ไปถึง ไม่ใช่แค่เพียง Refresh เฉพาะ Pivot table นั้นๆ
   4.2 หาก 1 Connection มี Pivot table หลาย pivot อ้างถึง   การ Refresh connection นั้นๆ จะทำการ Refresh ทุก Pivot table ที่อ้างถึง Connection ที่ Refresh
   4.3 ดังนั้น การที่เราเข้าใจว่าจะ Refresh เฉพาะ Pivot table ที่ต้องการนั้นไม่จริง  เพราะหาก Connection ที่ Pivot Refer มี Pivot table อื่นๆอ้างถึงอยู่ด้วย  ทุก Pivot table ที่อ้างถึง Connection นั้นจะถูก Refresh ทั้งหมด

5. ข้อแนะนำสำหรับการสร้าง Pivot table ใน Work book
   5.1 หาก Pivot table แต่ละ pivot ที่สร้างขึ้น ใช้เวลานานในการ Refresh Data ควรสร้าง Connection ใน Work book แยกกันเพราะเวลา Refresh จะได้ไม่กระทบกับ Pivot อื่นๆ
   5.2 Pivot table ที่สามารถ Refresh Data ได้รวดเร็วสามารถใช้ Connection เดียวกันได้