简体   繁体   English

Power Query自定义列从不同行获取数据

[英]Power Query custom column to get data from a different row

This might be simple, but I can't wrap my head around it... I need a Custom Column in Power Query to return data from a specific column in another row这可能很简单,但我无法理解它......我需要 Power Query 中的自定义列来返回另一行中特定列的数据

Currently I have location data for all employee ID numbers, but for some, the location is blank.目前我有所有员工 ID 号的位置数据,但对于某些员工,该位置是空白的。 In this data, in any given employee's row, there is also their manager's ID#.在此数据中,在任何给定员工的行中,还有他们经理的 ID#。

What I need is a custom row that returns the employee's manager's location IF the employee's location is blank.我需要的是一个自定义行,如果员工的位置为空,则返回员工经理的位置。 For now, I am not looking to fix manager's that also do not have a location, if the manager's location is blank, I am ok with the Employee's pulling blanks in these cases only.现在,我不打算修复也没有位置的经理,如果经理的位置是空白的,我只在这些情况下接受员工的空白。

Any help would be greatly appreciated.任何帮助将不胜感激。

Merge the table on top of itself using the manager ID column on top matched to the employee ID column on bottom.使用顶部的经理 ID 列与底部的员工 ID 列匹配,合并顶部的表。 Expand location using arrows atop column.使用列顶部的箭头展开位置。 Add column custom column that says添加列自定义列说

=if [location] =null then [newcolumnyouexpanded] else [location] =if [location] =null then [newcolumnyouexpanded] else [location]

在此处输入图像描述

let  Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Merged Queries" = Table.NestedJoin(Source, {"ManagerID"}, Source, {"ID"}, "Source", JoinKind.LeftOuter),
#"Expanded Source" = Table.ExpandTableColumn(#"Merged Queries", "Source", {"Location"}, {"Manager.Location"}),
#"Added Custom" = Table.AddColumn(#"Expanded Source", "CombinedLocation", each if [Location]=null then [Manager.Location] else [Location]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Location", "Manager.Location"})
in  #"Removed Columns"

You can do something like this:你可以这样做:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddLocation 
        = Table.AddColumn(
            Source,
            "LocationCleaned",
            (a) => 
                if  a[location] = null then 
                    Table.SelectRows(Source, each [emp ID] = a[manager] )[location]{0}
                else 
                    a[location]
        )
in
    AddLocation

在此处输入图像描述

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

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