Power Query 中一列中的重复值与另一列中的不同类别

问题描述 投票:0回答:1

如果您观察下表,每个资产都有多个 SourceType,并且每个 SourceType 的状态都在“状态”列中提及。

姓名 来源类型 日期 状态
资产1 安全 2024年3月27日 活跃
资产1 申请 2024年3月24日 未激活
资产1 系统 2024年3月27日 活跃
资产2 系统 2024年3月27日 活跃
资产2 安全 2024年2月21日 未激活
资产2 申请 2023年6月15日 未激活
资产3 系统 2024年3月27日 活跃
资产3 安全 2024年2月21日 活跃
资产3 申请 2023年6月15日 活跃

我期待以下输出:

姓名 来源类型 日期 状态
资产1 安全 2024年3月27日 未激活
资产1 申请 2024年3月24日 未激活
资产1 系统 2024年3月27日 未激活
资产2 系统 2024年3月27日 未激活
资产2 安全 2024年2月21日 未激活
资产2 申请 2023年6月15日 未激活
资产3 系统 2024年3月27日 活跃
资产3 安全 2024年2月21日 活跃
资产3 申请 2023年6月15日 活跃

如果任意一个 SourceType 为“In-Active”,则另外 2 个 SourceType 也应更新为“In-Active”。 当所有 3 个 SourceType 都处于 Active 状态时,应该提到 Active。

如果有人能帮助我,我将不胜感激。谢谢你:)

powerbi conditional-statements duplicates powerquery
1个回答
0
投票

我想这取决于您是仅按姓名分组还是按姓名和日期分组

只是名字

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Name"}, {{"data", each 
    let base=_,     
    Inactivecount= List.Sum(List.Transform(base[Status], each if _="In-Active" then 1 else 0)),
    ActiveCount= List.Sum(List.Transform(base[Status], each if _="Active" then 1 else 0)),
    New = Table.AddColumn(base,"Status2", each if ActiveCount=Table.RowCount(base) then "Active" else if Inactivecount>0 then "In-Active" else [Status]),
    #"Removed Columns" = Table.RemoveColumns(New,{"Status"})
    in #"Removed Columns", type table }}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"SourceType", "Date", "Status2"}, {"SourceType", "Date", "Status"})
in  #"Expanded data"

姓名和日期

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Name","Date"}, {{"data", each 
    let base=_,     
    Inactivecount= List.Sum(List.Transform(base[Status], each if _="In-Active" then 1 else 0)),
    ActiveCount= List.Sum(List.Transform(base[Status], each if _="Active" then 1 else 0)),
    New = Table.AddColumn(base,"Status2", each if ActiveCount=Table.RowCount(base) then "Active" else if Inactivecount>0 then "In-Active" else [Status]),
    #"Removed Columns" = Table.RemoveColumns(New,{"Status"})
    in #"Removed Columns", type table }}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"SourceType", "Status2"}, {"SourceType", "Status"})
in  #"Expanded data"
© www.soinside.com 2019 - 2024. All rights reserved.