如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

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

How to calculate max and min values from a comma-separated string column in Power BI?

问题

Max Value = MAX(VALUE(SPLIT([Spalte 2], ",")))
Min Value = MIN(VALUE(SPLIT([Spalte 2], ",")))

英文:

I have a table in Power BI that contains a column with comma-separated values, like this(Spalte 2 actually has 10000 points, i have shown 10 points):

Spalte 1 Spalte 2
1 23,45,66,55,11,333,44,55,66,77
2 233,45,66,55,11,333,44,55,66,77
3 23,45,66,55,11,333,44,55,66,773
... ...

I want to add two new columns to the table that show the maximum and minimum values of each row, based on the values in the "Spalte 2" column. For example:

Spalte 1 Spalte 2 Max Value Min Value
1 23,45,66,55,11,333,44,55,66,77 333 11
2 233,45,66,55,11,333,44,55,66,77 333 11
3 23,45,66,55,11,333,44,55,66,773 773 11
... ... ... ...

I tried using the "SPLIT" function, but it did not work. Can someone suggest a DAX formula that can achieve this? Thank you.

Max Value = MAX(VALUE(SPLIT([Spalte 2],",")))
Min Value = MIN(VALUE(SPLIT([Spalte 2],",")))

答案1

得分: 0

在DAX中,你可能可以使用PATH()函数来完成这个任务,但这将是DAX的一种糟糕用法,不是正确的方法。你的数据结构不正确,需要在Power Query中重新组织数据,然后再使用DAX进行分析。

在Power Query中执行以下步骤:

  1. 起始表格:

    如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

  2. 通过分隔符拆分列并拆分为行:

    如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

    如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

现在你有两个选择。你可以在Power Query中进行分组:

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

或者将其不分组,加载到你的模型中,并编写两个度量值,如下所示:

  • Max Measure = MAX('Table'[Spalte 2])
  • Min Measure = MIN('Table'[Spalte 2])

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

英文:

You could possibly do this in DAX using PATH() functions but that would be a terrible use of DAX and not the right approach. Your data is in the wrong shape and needs to be reshaped in Power Query before doing analysis in DAX.

Do the following in Power Query:

Starting table:

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

Split column by delimiter and split to rows:

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

You now have 2 choices. You can either group by in Power Query:

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

Or leave it ungrouped, load to your model and write 2 measures as follows:

Max Measure = MAX('Table'[Spalte 2]) 
Min Measure = MIN('Table'[Spalte 2]) 

如何在Power BI中从逗号分隔的字符串列中计算最大和最小值?

答案2

得分: 0

以下是代码部分的翻译:

```Power Query`中的备选方案,如果您想测试性能。

List.Max( List.Transform (Text.Split([Spalte 2], ","), each Number.From(_)))


请注意,这是您提供的代码的翻译,没有其他内容。

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

Here is an alternative in PQ if you want to test performance. 

    List.Max( List.Transform (Text.Split([Spalte 2], &quot;,&quot;), each Number.From(_)))

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


[![enter image description here][2]][2]


  [1]: https://i.stack.imgur.com/QwkSy.png
  [2]: https://i.stack.imgur.com/Xpm5X.png

</details>



huangapple
  • 本文由 发表于 2023年3月7日 05:25:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655999.html
匿名

发表评论

匿名网友

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

确定