简体   繁体   中英

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.

Is it possible to force powerPivot to show value by its column name?

If you don't mind using Power Query, you can get to this fairly easily:

在此处输入图片说明

Here's how:

1. Add your tables as sources in Power Query. In Excel 2016, you can do that by clicking on a table, then on Data -> From Table. This will open Power Query with your selected table loaded. 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.

a. Click on your Issues query, in the queries list on the left side of your screen. That will open the Issues query.

b. Click Home -> Merge Queries (drop-down) -> Merge Queries as New.

在此处输入图片说明

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. (Of course, you would use the names of your tables, instead of Issues and Extended.)

在此处输入图片说明

Your new query will look something like this:

在此处输入图片说明

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.

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

在此处输入图片说明

b. Select the customName column then Transform -> Pivot Column. Fill in the dialog window that pops up like this, below, and click OK.

在此处输入图片说明

4. Clean up. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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