简体   繁体   English

PowerPivot一对多价值

[英]PowerPivot One to Many Value

I have two tables. 我有两张桌子。

An Issue table 发行表

+----+-------+
| ID | Name  |
+----+-------+
|  1 | task1 |
|  2 | task2 |
|  3 | task3 |
+----+-------+

And table that extends issue by custom fields 和通过自定义字段扩展问题的表

+----+---------+------------+------------+
| ID | issueId | customName |    val     |
+----+---------+------------+------------+
|  1 |       1 | age        | 22         |
|  2 |       1 | speed      | 56kmph     |
|  3 |       1 | startDate  | 03.03.2015 |
+----+---------+------------+------------+

Problem in PowerPivot is that, when I select Issue as a Row, customField as Columns and val as a Value at place of Value Excel automatically aggregate using "Count of Value" which shows fields count, and for speed, startDate etc. excel shows "1", not the propper val of it. PowerPivot中的问题是,当我选择“问题”作为行,“ customField”作为“列”和“ val”作为“值”时,Excel自动使用“值的计数”自动聚合,该“值的计数”显示字段计数,而对于速度,startDate等,excel显示“ 1“,而不是适当的值。

Is it possible to force powerPivot to show value by its column name? 是否可以强制powerPivot通过其列名显示值?

If you don't mind using Power Query, you can get to this fairly easily: 如果您不介意使用Power Query,则可以轻松地做到这一点:

在此处输入图片说明

Here's how: 这是如何做:

1. Add your tables as sources in Power Query. 1.在Power Query中将表添加为源。 In Excel 2016, you can do that by clicking on a table, then on Data -> From Table. 在Excel 2016中,可以通过单击表,然后单击“数据”->“从表”来实现。 This will open Power Query with your selected table loaded. 这将打开加载了所选表的Power Query。 The table will be listed under Queries, on the left side of the screen. 该表将在屏幕左侧的“查询”下列出。

Once you've loaded your first table as a source. 一旦您将第一个表加载为源。 Probably the simplest way to add the next one (by way of explanation anyhow) is to click File -> Close and Load, and do what you did previously, this time for the second source. 添加下一个(可能是通过解释的方式)的最简单方法可能是单击“文件”->“关闭并加载”,然后为第二个来源执行您之前的操作。

(When you Close and Load, a new tab will be created in your workbook, with the results of the new Query...which right now would just look like a duplicate of your original source table.) (当您关闭并加载时,将在工作簿中创建一个新选项卡,其中包含新查询的结果...现在看起来就像是原始源表的副本。)

2. Merge (join) your two queries. 2.合并(合并)您的两个查询。

a. 一种。 Click on your Issues query, in the queries list on the left side of your screen. 单击您的问题查询,在屏幕左侧的查询列表中。 That will open the Issues query. 这将打开“问题”查询。

b. b。 Click Home -> Merge Queries (drop-down) -> Merge Queries as New. 单击主页->合并查询(下拉列表)->将查询合并为新的。

在此处输入图片说明

c. C。 Fill in the dialog window like below and click OK. 如下所示填写对话框窗口,然后单击“确定”。 Make sure to select the columns you want to match on--highlighted in green here. 确保选择要匹配的列-在此处以绿色突出显示。 This will create a new query, most likely named Merge. 这将创建一个新查询,最有可能名为Merge。 (Of course, you would use the names of your tables, instead of Issues and Extended.) (当然,你可以使用你的表的名称,而不是问题和扩展。)

在此处输入图片说明

Your new query will look something like this: 您的新查询将如下所示:

在此处输入图片说明

d. d。 Click on the 点击 在此处输入图片说明 button to expand the tables in the column of tables and make selections, like these, from the drop-down window and click OK. 按钮以展开表格列中的表格,并从下拉窗口中进行选择,然后单击“确定”。

在此处输入图片说明

You'll get a table something like this: 您会得到一个类似这样的表:

在此处输入图片说明

3. Pivot your customName column. 3.旋转您的customName列。

a. 一种。 You can't pivot a column with nulls, so select the customName column, then Transform -> Replace Values, and enter these settings in the dialog window that pops up, then click OK (the Replace With box is left empty): 您不能将列设置为空,因此选择customName列,然后选择“转换”->“替换值”,然后在弹出的对话框窗口中输入以下设置,然后单击“确定”(“替换为”框为空):

在此处输入图片说明

b. b。 Select the customName column then Transform -> Pivot Column. 选择customName列,然后选择Transform-> Pivot Column。 Fill in the dialog window that pops up like this, below, and click OK. 填写如下所示的弹出对话框,然后单击“确定”。

在此处输入图片说明

4. Clean up. 4.清理。 Select all the columns you want to keep, then click Home -> Remove Columns (drop-down) -> Remove Other Columns: 选择要保留的所有列,然后单击主页->删除列(下拉列表)->删除其他列:

在此处输入图片说明

You'll end up with something like this: 您将得到如下所示的结果:

在此处输入图片说明

When you Close and Load, you'll get a new tab with the final table in it. 当您关闭并加载时,您将获得一个带有最终表的新标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM