<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>简单生活 —— Kevin Yang的博客 &#187; BI</title> <atom:link href="http://www.imkevinyang.com/tags/bi/feed" rel="self" type="application/rss+xml" /><link>http://www.imkevinyang.com</link> <description>It&#039;s all about sharing</description> <lastBuildDate>Mon, 06 Sep 2010 08:00:00 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>OLAP中的AverageOfChildren聚合方式</title><link>http://www.imkevinyang.com/2009/08/olap%e4%b8%ad%e7%9a%84averageofchildren%e8%81%9a%e5%90%88%e6%96%b9%e5%bc%8f.html</link> <comments>http://www.imkevinyang.com/2009/08/olap%e4%b8%ad%e7%9a%84averageofchildren%e8%81%9a%e5%90%88%e6%96%b9%e5%bc%8f.html#comments</comments> <pubDate>Mon, 10 Aug 2009 15:52:00 +0000</pubDate> <dc:creator>Kevin Yang</dc:creator> <category><![CDATA[BI/数据库]]></category> <category><![CDATA[Analysis Services]]></category> <category><![CDATA[AverageOfChildren聚合方式]]></category> <category><![CDATA[BI]]></category> <category><![CDATA[OLAP]]></category> <category><![CDATA[平均值]]></category><guid isPermaLink="false">http://www.imkevinyang.com/2009/08/olap%e4%b8%ad%e7%9a%84averageofchildren%e8%81%9a%e5%90%88%e6%96%b9%e5%bc%8f.html</guid> <description><![CDATA[<p>BI项目中，我们经常需要设计“平均值”这样的指标，例如电子商务中的平均销售额，Web分析中的平均访问时长，等等。而Analysis Service中提供了一个“AverageOfChildren”的聚合方式，看上去好像就是为了这样的需求而设计的。</p><p>但是测试结果却发现，得到的数据根本就不是我们期望的。后来查资料找到了关于这个聚合方式的说明：</p><blockquote><p>AverageOfChildren——对某个成员的聚合值等于其所有子成员的平均值。</p></blockquote><p>这是什么意思呢？假设我&#8230;</p>]]></description> <content:encoded><![CDATA[<p>BI项目中，我们经常需要设计“平均值”这样的指标，例如电子商务中的平均销售额，Web分析中的平均访问时长，等等。而Analysis Service中提供了一个“AverageOfChildren”的聚合方式，看上去好像就是为了这样的需求而设计的。</p><p>但是测试结果却发现，得到的数据根本就不是我们期望的。后来查资料找到了关于这个聚合方式的说明：</p><blockquote><p>AverageOfChildren——对某个成员的聚合值等于其所有子成员的平均值。</p></blockquote><p>这是什么意思呢？假设我定义了一个“总销售额”和“平均销售额”这两个指标。当我看中国的数据的时候，假设中国的总销售额是34000万的话，因为中国下面有34个省级行政区（34个Member），因此平均销售额就是1000万。这是按照字面上的理解。但实际上，这样理解是错误的。MSDN上给出的解释并没有明确指明，<strong><font color="#008000">AverageOfChildren这个聚合方式只是针对时间维度起作用</font></strong>。</p><p>在Analysis Service中内置了很多常见的维度类型，如时间维度，地理纬度，帐户维度等。你可以将你创建的维度的“类型”属性标记为内置的维度类型。这样的好处是，Analysis Service对这些标记为特殊类型的维度有额外的支持。例如如果你的Cube中包含一个标记为“时间维度”类型的维度时，那么你就可以在Mdx中使用和时间相关的函数，如Ytd等。类似的，AverageOfChildren这个聚合类型也是需要时间维度的支持，你首先需要在工程中显式指定至少一个时间维度。这个聚合方式的意义就是对所有的时间——以天为单位——求平均值。例如当前时间维度选择的成员是[2003年]，而03年有销售额数据的共有365天，那么</p><p><strong><font color="#008000">AverageOfChildren(销售额） =&#160; 总销售额 / 365</font></strong></p><p>如果范围再进一步缩小，选择[2003年3月份]，由于3月份每天都有销售额，因此AverageOfChildren就等于总销售额除以31。你可以按具体日期去查看，你会发现，每天的总销售额和平均销售额是一样的。这是因为具体日期的粒度已经是最小的了。</p><p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/08/image_thumb8.png" width="334" height="400" /></p><p>由于这个AverageOfChildren聚合方式只是针对时间维度的，不能满足大量的应用场景，因此通常我们都需要自己定义这样一个求平均值的计算指标。公式很简单：</p><p>平均值=总值 / 维度成员个数</p><p>例如我们想看月利润平均值，那么首先我们定义一个“总利润”的指标，那么</p><p>月利润平均值 = 总利润 / Count([Time].[CalendarMonth].children)</p><p align="right">——<a href="http://www.imkevinyang.com/"><em><strong>Kevin Yang</strong></em></a></p>标签：<a href="http://www.imkevinyang.com/tags/analysis-services" title="Analysis Services" rel="tag">Analysis Services</a>, <a href="http://www.imkevinyang.com/tags/averageofchildren%e8%81%9a%e5%90%88%e6%96%b9%e5%bc%8f" title="AverageOfChildren聚合方式" rel="tag">AverageOfChildren聚合方式</a>, <a href="http://www.imkevinyang.com/tags/bi" title="BI" rel="tag">BI</a>, <a href="http://www.imkevinyang.com/categories/techarticles/businessintelligence" title="BI/数据库" rel="tag">BI/数据库</a>, <a href="http://www.imkevinyang.com/tags/olap" title="OLAP" rel="tag">OLAP</a>, <a href="http://www.imkevinyang.com/tags/%e5%b9%b3%e5%9d%87%e5%80%bc" title="平均值" rel="tag">平均值</a><br /><h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4><ul class="st-related-posts"><li><a href="http://www.imkevinyang.com/2010/05/64%e4%bd%8d%e7%b3%bb%e7%bb%9f%e4%b8%8biis7-isapi%e5%a4%84%e7%90%86%e5%99%a8%e5%8a%a0%e8%bd%bd%e5%a4%b1%e8%b4%a5.html" title="64位系统下IIS7 ISAPI处理器加载失败 (2010/05/05)">64位系统下IIS7 ISAPI处理器加载失败</a> (2010/05/05)</li><li><a href="http://www.imkevinyang.com/2009/05/analysis-service-2005-olap-best-practice-white-paper.html" title="Analysis Service 2005 OLAP Best Practice White Paper (2009/05/22)">Analysis Service 2005 OLAP Best Practice White Paper</a> (2009/05/22)</li><li><a href="http://www.imkevinyang.com/2009/04/analysis-services-2005-olap%e8%ae%be%e8%ae%a1%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5.html" title="Analysis Services 2005 OLAP设计最佳实践 (2009/04/02)">Analysis Services 2005 OLAP设计最佳实践</a> (2009/04/02)</li><li><a href="http://www.imkevinyang.com/2010/04/analysis-services%ef%bc%9a%e4%bd%a0%e5%ba%94%e8%af%a5%e4%bd%bf%e7%94%a8%e5%a4%9a%e5%af%b9%e5%a4%9a%e7%bb%b4%e5%ba%a6%e5%90%97%ef%bc%9f.html" title="Analysis Services：你应该使用多对多维度吗？ (2010/04/12)">Analysis Services：你应该使用多对多维度吗？</a> (2010/04/12)</li><li><a href="http://www.imkevinyang.com/2009/03/bids%e9%83%a8%e7%bd%b2%e6%97%b6%e5%87%ba%e7%8e%b0%e5%85%83%e6%95%b0%e6%8d%ae%e7%ae%a1%e7%90%86%e5%99%a8%e5%8f%91%e7%94%9f%e9%94%99%e8%af%af.html" title="BIDS部署时出现元数据管理器发生错误 (2009/03/13)">BIDS部署时出现元数据管理器发生错误</a> (2009/03/13)</li><li><a href="http://www.imkevinyang.com/2010/07/ssas%e5%a4%84%e7%90%86%e6%97%b6%e6%89%be%e4%b8%8d%e5%88%b0%e5%b1%9e%e6%80%a7%e9%94%ae%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95.html" title="SSAS处理时&ldquo;找不到属性键&rdquo;的解决办法 (2010/07/19)">SSAS处理时&ldquo;找不到属性键&rdquo;的解决办法</a> (2010/07/19)</li><li><a href="http://www.imkevinyang.com/2009/10/%e5%85%a8%e5%8d%8a%e8%a7%92%e7%a9%ba%e6%a0%bc%e5%af%bc%e8%87%b4%e7%9a%84analysis-service%e5%a4%84%e7%90%86%e9%94%99%e8%af%af.html" title="全半角空格导致的Analysis Services处理错误 (2009/10/09)">全半角空格导致的Analysis Services处理错误</a> (2009/10/09)</li><li><a href="http://www.imkevinyang.com/2009/11/%e6%9d%83%e9%99%90%e5%af%bc%e8%87%b4%e7%9a%84analysis%e6%80%a7%e8%83%bd%e8%ae%a1%e6%95%b0%e5%99%a8%e5%9c%a8vistawin2008%e4%b8%8b%e5%a4%b1%e6%95%88%e7%9a%84%e9%97%ae%e9%a2%98.html" title="权限不足导致的Analysis性能计数器在Vista/win2008下失效的问题 (2009/11/12)">权限不足导致的Analysis性能计数器在Vista/win2008下失效的问题</a> (2009/11/12)</li><li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3%e7%bb%b4%e5%ba%a6%e6%88%90%e5%91%98%e4%b8%ad%e7%9a%84%e9%9d%9e%e6%b3%95xml%e5%ad%97%e7%ac%a6%e5%af%bc%e8%87%b4%e7%9a%84%e6%9f%a5%e8%af%a2%e9%94%99%e8%af%af-2.html" title="解决维度成员中的非法Xml字符导致的查询错误 (2009/09/19)">解决维度成员中的非法Xml字符导致的查询错误</a> (2009/09/19)</li></ul>]]></content:encoded> <wfw:commentRss>http://www.imkevinyang.com/2009/08/olap%e4%b8%ad%e7%9a%84averageofchildren%e8%81%9a%e5%90%88%e6%96%b9%e5%bc%8f.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>