功率查询自定义功能以从逗号分隔字符串检索部分

问题描述 投票:0回答:1
DeVilliers Street,惠灵顿北部,惠灵顿,西开普省,南非

米尔街,帕尔,西开普省,南非

    某些地址有5个部分,有4个部分有4个部分。 我想在电源查询中创建一个自定义函数,我可以根据其所拥有的部分来从地址中检索特定部分。
  • (Location,SectionNr) => let Sections = Text.Split(Location,","), Section = Sections[SectionNr] in Section
  • 例如,从上面的地址获得该省:
GetSection("De Villiers Street, Wellington North, Wellington, Western Cape, South Africa ",4)

...应该返回西开普

GetSection("Main Street, Paarl, Western Cape, South Africa",3)
...应该返回西开普

对其进行了探测:

= (Location,SectionNr) => let Sections = Text.Split(Location,","), SectionValue = Sections{SectionNr-1} in SectionValue
问题是我是[]括号而不是{}括号。同样,由于列表索引从0开始,我更喜欢将sectionnr发送为1-n,所以我只是从sectionnr.

中减去1。

powerbi powerquery custom-functions-excel
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.