根据语言在PowerBI表中筛选重复行。

huangapple go评论126阅读模式
英文:

Filter duplicate rows in powerbi table based on language

问题

你想在Power BI中过滤掉那些id出现超过一次的行,根据以下条件进行过滤:

如果行的语言是"fi",则保留该行。如果找不到"fi"语言,则保留"en"语言。如果都找不到,则保留"se"语言。因此,表中的结果行将是1、2、5、6。

有办法像这样进行筛选吗?我在Power BI中还比较新手,迄今为止还没有成功实现这个。

【注意:这是你要求的翻译部分。】

英文:

I have the following table in Power BI:

index id language value
1 12 fi value_in_fi
2 312 fi value_in_fi
3 312 en value_in_en
4 312 se value_in_se
5 22 fi value_in_fi
6 1 se value_in_se
7 22 en value_in_en

I would like to filter out rows from the table where the id appears more than once, under the following conditions:

If the row's language is "fi," keep that row. If the language "fi" is not found, keep the language "en." If neither is found, keep the language "se." So, the resulting rows in the table would be 1, 2, 5, 6.

Is there any way to do filtering like this? I'm kind of new to powerbi so haven't succeeded in this so far

答案1

得分: 2

以下是你的翻译:

你可以在你的表格上应用一些额外的转换。以下是你的表格的Power Query代码。前往你的表格的高级编辑器,并使用下面的代码-

不要忘记在新代码的第1行更改previous_step_name

    //.... 你现有的代码

    //新代码从这里开始    
    #"添加自定义" = Table.AddColumn(#"previous_step_name", "自定义", each if [language] = "fi" then 1 else if [language] = "en" then 2 else if [language] = "se" then 3 else 4),
    #"分组表格" = Table.Group(#"添加自定义", {"id"}, {{"最小值", each List.Min([自定义]), 类型 number}}),
    #"合并查询" = Table.NestedJoin(#"添加自定义", {"id", "自定义"}, #"分组表格", {"id", "最小值"}, "分组表格", JoinKind.Inner),
    #"删除列" = Table.RemoveColumns(#"合并查询",{"分组表格", "自定义"})
in
    #"删除列"```

以下是输出-

[![enter image description here][1]][1]


----

你的新代码将如下所示-

```let 
    Source = PostgreSQL.Database("localhost", "test"), 
    table_name = Source{[Schema="testschema",Item="table_name"]}[Data], 


    //新代码从这里开始    
    #"添加自定义" = Table.AddColumn(#"table_name", "自定义", each if [language] = "fi" then 1 else if [language] = "en" then 2 else if [language] = "se" then 3 else 4),
    #"分组表格" = Table.Group(#"添加自定义", {"id"}, {{"最小值", each List.Min([自定义]), 类型 number}}),
    #"合并查询" = Table.NestedJoin(#"添加自定义", {"id", "自定义"}, #"分组表格", {"id", "最小值"}, "分组表格", JoinKind.Inner),
    #"删除列" = Table.RemoveColumns(#"合并查询",{"分组表格", "自定义"})
in
    #"删除列"```

<details>
<summary>英文:</summary>

You can apply some additional transformation on your table. Here below is the **Power Query** code for your table. Go to **Advance Editor** of your table and use this below code-

Don&#39;t forget to change the **previous_step_name** in line 1 of the new code.

let
//.... your existing code

//New code starts here    
#&quot;Added custom&quot; = Table.AddColumn(#&quot;previous_step_name&quot;, &quot;Custom&quot;, each if [language] = &quot;fi&quot; then 1 else if [language] = &quot;en&quot; then 2 else if [language] = &quot;se&quot; then 3 else 4),
#&quot;grouped_table&quot; = Table.Group(#&quot;Added custom&quot;, {&quot;id&quot;}, {{&quot;min&quot;, each List.Min([Custom]), type number}}),
#&quot;Merged Queries&quot; = Table.NestedJoin(#&quot;Added custom&quot;, {&quot;id&quot;, &quot;Custom&quot;}, #&quot;grouped_table&quot;, {&quot;id&quot;, &quot;min&quot;}, &quot;grouped_table&quot;, JoinKind.Inner),
#&quot;Removed Columns&quot; = Table.RemoveColumns(#&quot;Merged Queries&quot;,{&quot;grouped_table&quot;, &quot;Custom&quot;})

in
#"Removed Columns"


Here is the output-

[![enter image description here][1]][1]


----

Your new code will be like below-

let
Source = PostgreSQL.Database("localhost", "test"),
table_name = Source{[Schema="testschema",Item="table_name"]}[Data],

//New code starts here    
#&quot;Added custom&quot; = Table.AddColumn(#&quot;table_name&quot;, &quot;Custom&quot;, each if [language] = &quot;fi&quot; then 1 else if [language] = &quot;en&quot; then 2 else if [language] = &quot;se&quot; then 3 else 4),
#&quot;grouped_table&quot; = Table.Group(#&quot;Added custom&quot;, {&quot;id&quot;}, {{&quot;min&quot;, each List.Min([Custom]), type number}}),
#&quot;Merged Queries&quot; = Table.NestedJoin(#&quot;Added custom&quot;, {&quot;id&quot;, &quot;Custom&quot;}, #&quot;grouped_table&quot;, {&quot;id&quot;, &quot;min&quot;}, &quot;grouped_table&quot;, JoinKind.Inner),
#&quot;Removed Columns&quot; = Table.RemoveColumns(#&quot;Merged Queries&quot;,{&quot;grouped_table&quot;, &quot;Custom&quot;})

in
#"Removed Columns"



  [1]: https://i.stack.imgur.com/wcjG2.png

</details>



huangapple
  • 本文由 发表于 2023年5月25日 14:09:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76329368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定