提取列中字母前的所有内容。

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

PowerQuery Extract everything before alphabet from a column

问题

我正在清洗数据并尝试找出从列中提取数据的最佳方法是什么?所有变量的长度和格式都不相同,但我想提取第一个字母和它之前的所有内容。例如:

示例数据:12345A123; 23456B000; 45678D93

输出:12345A; 23456B; 45678D

英文:

I am cleaning data and trying to figure out what the best way to extract data from a column is? None of the variables are same length or format but I want to extract the first ALPHABET and everything BEFORE it. For example:

Sample Data: 12345A123; 23456B000; 45678D93

Output: 12345A; 23456B; 45678D

答案1

得分: 1

在您提供的文本中,以下是需要翻译的部分:

Add a custom column and type in:

添加一个自定义列并输入:

Splitter.SplitTextByCharacterTransition({"A".."Z", "a".."z"}, {"0".."9"})([Column1]){0}

英文:

提取列中字母前的所有内容。

提取列中字母前的所有内容。

Add a custom column and type in:

Splitter.SplitTextByCharacterTransition({"A".."Z", "a".."z"}, {"0".."9"})([Column1]){0}

答案2

得分: 1

= Text.Range([Column1], 0, Text.PositionOfAny([Column1],{"a".."z","A".."Z"}) + 1)

英文:

How about adding column, custom column, with formula

 = Text.Range([Column1],0,Text.PositionOfAny([Column1],{"a".."z","A".."Z"})+1)

答案3

得分: 1

I don't think you really did a search for this. It's in Microsoft's documentation.

I started with your list:

12345A123
23456B000
45678D93

Then I clicked on "Transform," "Split Column," then "Non-Digit to Digit." As a last step, I removed the second column the split produced.

提取列中字母前的所有内容。

This is the output:

12345A
23456B
45678D

And here is the M code:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Split Column by Character Transition" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column1.1", "Column1.2"}),
#"Removed Columns" = Table.RemoveColumns(#"Split Column by Character Transition",{"Column1.2"})
in
#"Removed Columns"

英文:

I don't think you really did a search for this. It's in Microsoft's documentation.

I started with your list:

12345A123
23456B000
45678D93

Then I clicked on "Transform", "Split Column", then "Non-Digit to Digit". As a last step, I removed the second column the split produced.

提取列中字母前的所有内容。

This is the output:

12345A
23456B
45678D

And here is the M code:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Character Transition" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column1.1", "Column1.2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Character Transition",{"Column1.2"})
in
    #"Removed Columns"

huangapple
  • 本文由 发表于 2023年2月9日 00:52:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389108.html
匿名

发表评论

匿名网友

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

确定