这是我的OLAP多维数据集架构
<?xml version="1.0"?>
<Schema name="mySchema">
<Cube name="myCube">
<Table name="fact_access_logs_views"/>
<Dimension name="Countries" foreignKey="country_code_id">
<Hierarchy hasAll="true" primaryKey="country_code_id">
<Table name="dim_country_code"/>
<Level name="CountryCodes" column="CountryCode" uniqueMembers="false"/>
</Hierarchy>
</Dimension>
<Dimension name="Channels" foreignKey="channel_id">
<Hierarchy hasAll="true" primaryKey="channel_id">
<Table name="dim_channel"/>
<Level name="Channels" column="shortname_chn" uniqueMembers="false"/>
</Hierarchy>
</Dimension>
<Dimension name="Time" foreignKey="access_time_id">
<Hierarchy hasAll="true" primaryKey="access_time_id">
<Table name="dim_time_access"/>
<Level name="Year" column="Year" uniqueMembers="false"/>
<Level name="Month" column="Month" uniqueMembers="false"/>
<Level name="Date" column="Date" uniqueMembers="false"/>
<Level name="Hour" column="Hour" uniqueMembers="false"/>
</Hierarchy>
</Dimension>
<Measure name="View Count" column="id" aggregator="count" formatString="#,###"/>
</Cube>
</Schema>
我要做的是根据观看次数找出前十个国家,并在每个国家/地区进一步查看前十个频道。请帮我构建一个MDX查询。我试图遵循这个https://msdn.microsoft.com/en-us/library/ms145579 但最终在查看多维数据集时遇到错误。
答案 0 :(得分:1)
使用TopCount和Generate,你可以这样做。
TopCount将为您提供按您选择的度量排序的最高成员。
观点排名前10位的国家:
TopCount([Countries].[CountryCode].[CountryCode],10 ,[Measures].[View Count] )
然后,您将使用generate和currentmember迭代第一组Top Countries 并使用上面相同的逻辑但使用频道来获取顶级频道。
WITH
SET TOPCHANNELSperTOPCOUNTRY AS
Generate
(
TopCount
(
[Countries].[CountryCode].[CountryCode]
,10
,[Measures].[View Count]
)
,TopCount
(
(
[Countries].[CountryCode].CurrentMember
,[Channels].[Channels].[Channels]
)
,10
,[Measures].[View Count]
)
)
SELECT
[Measures].[View Count] ON 0
,TOPCHANNELSperTOPCOUNTRY ON 1
FROM [myCube];
(对不起,如果某些维度名称或成员不正确)...
答案 1 :(得分:-1)
您可以使用Top Count,Generate和CrossJoin实现此目的。
IMAGE CREATED CREATED BY SIZE COMMENT
147465a83f44 21 seconds ago /bin/sh -c conda install -y --file production 618.3 MB
ac247a09a6b9 About a minute ago /bin/sh -c #(nop) WORKDIR /pybank 0 B
ee7012dc6c28 About a minute ago /bin/sh -c #(nop) ADD dir:9d26c17d067275f3836 62.45 kB
2552d13402b6 3 hours ago /bin/sh -c #(nop) MAINTAINER Thomas Schmelzer 0 B
2fd9d2e11210 4 days ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 4 days ago /bin/sh -c #(nop) ENTRYPOINT ["/usr/bin/tini" 0 B
<missing> 4 days ago /bin/sh -c #(nop) ENV PATH=/opt/conda/bin:/us 0 B
<missing> 4 days ago /bin/sh -c apt-get install -y curl grep sed d 2.293 MB
<missing> 4 days ago /bin/sh -c echo 'export PATH=/opt/conda/bin:$ 133 MB
<missing> 4 days ago /bin/sh -c apt-get update --fix-missing && ap 195 MB
<missing> 4 days ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 LC_ALL=C.U 0 B
<missing> 4 days ago /bin/sh -c #(nop) MAINTAINER Kamil Kwiek <kam 0 B
<missing> 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:76679eeb94129df23c 125.1 MB
thomas