English 中文(简体)
Excel Pivot Table: Can 我分析了两个数据栏,因为它们是一栏?
原标题:Excel Pivot Table: Can I analyze two columns of data as if they were a single column?

我有一个表格来追踪部分转移交易。 这些数据按日期记录为数据表,有一人获得积极信贷,另一人是负信用。

Column
1 - Date
2 - Name
3 - Hours (Positive)
4 - Name
5 - Hours (Negative)

我希望有一个Pivot表,该表有一份单一的雇员名单和一份显示所涉期间净平衡的数字。

I tried to insert a Field (Field1) in the Pivot Table as a Calculated field of Hours (Negative Hours) and Hours2 (Positive Hours). But it treats the Carlos in the negative hours as a different person from Carlos with positive hours rather than creating a sum of Carlos net hours.
Basic Data
Basic Data

Expected Result
Expected Result

问题回答

您可以开脱表格,然后开张,特别是如果您有<条码>365/代码>。

我指定了数据表<代码>Shifts,你可以使用这一公式来公布数据。 它将适应<代码>Person-Hours的任何编号:

=LET(
    persCols, SEQUENCE(, (COLUMNS(Shifts) - 1) / 2, 2, 2),
    hrsCols, SEQUENCE(, (COLUMNS(Shifts) - 1) / 2, 3, 2),
    persons, TOCOL(CHOOSECOLS(Shifts, persCols)),
    hrs, TOCOL(CHOOSECOLS(Shifts, hrsCols)),
    VSTACK({"Person", "Hours"}, HSTACK(persons, hrs))
)

This results in a table:
enter image description here

And you can use the regular Excel pivot table wizard to create the result table in your desired format:
enter image description here

然而,也可通过电文,在Windows Excel 2010+和Microsoft 365(Windows或Ma)上提供。

这一解决办法还将针对任何数量的个人-人类配对栏。

使用权力

  • Select some cell in your Data Table
  • Data => Get&Transform => from Table/Range
  • When the PQ Editor opens: Home => Advanced Editor
  • Make note of the Table Name in Line 2
  • Paste the M Code below in place of what you see
  • Change the Table name in line 2 back to what was generated originally.
  • Read the comments and explore the Applied Steps to understand the algorithm
let

//Change next lines to reflect actual data source
    Source = Excel.CurrentWorkbook(){[Name="Shifts"]}[Content],


//can have multiple person-hour pairs after the first "Date" column
    personCols = List.Alternate(List.RemoveFirstN(Table.ColumnNames(Source),1),1,1,1),
    hoursCols = List.Alternate(List.RemoveFirstN(Table.ColumnNames(Source),1),1,1,0),
    typeSets = {{"Date", type date}} & List.Transform(personCols, each {_, type text}) & List.Transform(hoursCols, each {_, type number}),

//Set the data types
    #"Changed Type" = Table.TransformColumnTypes(Source, typeSets),

//Unpivot the data columns
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date"}, "Attribute", "Value"),

//Remove now uneeded columns
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Date", "Attribute"}),

//add a "shifted" column to facilitate matching the person with their hours
    #"Add Shifted Values" = Table.FromColumns(
        Table.ToColumns(#"Removed Columns") &
        {List.RemoveFirstN(#"Removed Columns"[Value],1) & {null}},
        type table[Person=text, Hours=number]),

//Remove unneeded rows
    #"Removed Alternate Rows" = Table.AlternateRows(#"Add Shifted Values",1,1,1),

//Group by Person and SUM the hours for each
    #"Grouped Rows" = Table.Group(#"Removed Alternate Rows", {"Person"}, {{"Sum", each List.Sum([Hours]), type number}}),

//Sort result in alphabetical order
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Person", Order.Ascending}})
in
    #"Sorted Rows"

“在此处的影像描述”/</a





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签