简体   繁体   English

如何使用 Power Bi 中的 Power Query 编辑器从两列的不同值的选择中创建新列

[英]How to create a new column from the select of the distinct values of two columns with Power Query Editor in Power Bi

I need to insert in a new column the distinct values of two columns using the Power Query Editor Power Bi.我需要使用 Power Query Editor Power Bi 在新列中插入两列的不同值。 Any ideas enter image description here guys?任何想法在这里输入图像描述

Here you go:干得好:

let
    Source = SomeTable
    firstCol = Source[FirstColumn],
    secondCol = Source[SecondColumn],
    thirdCol = List.Sort(List.RemoveNulls(List.Distinct(List.Combine( {firstCol, secondCol})))),
    #"TableResult" = Table.FromColumns({firstCol, secondCol, thirdCol}, {"First","Second","Combined"})

in
    #"TableResult"

This basically converts your first and second columns into lists, and combines them into one new list.这基本上将您的第一列和第二列转换为列表,并将它们组合成一个新列表。 Next, it transforms the new list a bit to match your requirements -- first by getting just the distinct values, then dropping any null values, and lastly sorting it in ascending order.接下来,它会稍微转换新列表以符合您的要求——首先只获取不同的值,然后删除任何空值,最后按升序对其进行排序。

Once that's done, we can take advantage of Table.FromColumns and create a table from our three lists.完成后,我们可以利用 Table.FromColumns 并从我们的三个列表中创建一个表。

That should get you where you're going.这应该让你去你要去的地方。

Thanks Ryan.谢谢瑞安。

My requirement was to create a distinct list of IP addresses from one of the columns in a Table.我的要求是从表中的一列创建一个不同的 IP 地址列表

Here's the code that worked for me.这是对我有用的代码。

= let
    Source = #"TABLENAME",
    firstCol  = #"TABLENAME"[Client Ip],
    IP = List.Distinct(firstCol),
    #"DistinctIP" = Table.FromColumns({IP}, {"IP"})
in
    #"DistinctIP"

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

相关问题 Power BI - 我如何将两个表中的两列 append 合并为具有不同值的一列 - Power BI - How do I append two columns from two tables into one column with distinct values 在 Power BI 中,当值(佣金)在不同日期发生变化时,如何从两个不同的表创建新列? - How to create a new column from two different tables when the values (commission) change in different dates, in power BI? 在矩阵中创建列,该列是Power BI中其他两个列的值的比率 - Create column in matrix that is a ratio of the values of two other columns in Power BI 在 Power BI 中对两列进行分组后创建一列值总和 - Create a column of sum of values after grouping two columns in Power BI 从 Power BI 中的两列创建新列 - Make new column from two columns in Power BI 如何在 Power BI Desktop 中的 DAX 中创建一个具有不同值的计算表 - how to create a calculated table having distinct values from one column in DAX inside Power BI Desktop Power BI 从列创建新行 - Power BI Create new Rows from Columns 如何从 Power BI 中的两行计算添加新列? - How to add new column from calculation on two rows in power BI? 如何在power bi中计算两列的新列值及其总和动态值? - How to calculate new column value from two columns and its sum dynamic value in power bi? Power Query 基于其他两个列创建新列 - Power Query Create New Column Based on Two Other Columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM