【问题标题】:Power query replacing values电源查询替换值
【发布时间】:2021-09-18 12:08:18
【问题描述】:

我正在替换 Power 查询中的值。我用在 excel 中创建的公式替换了正确的值,但现在我看到 Power 查询不能这样工作:/

the idea is to replace the value "½" to get the values as in this picture

无效的公式是这样的:

= Table.ReplaceValue(#"Odstranjeni stolpci","½","=Value(INDIRECT(ADDRESS(ROW();COLUMN()+1))-0.5)",Replacer.ReplaceValue,{"Column1" , "第 2 列", ....................

如果有人能帮我解决这个问题,那将有很大帮助!

【问题讨论】:

  • 标签“excel公式”是否适合这个Q??

标签: excel-formula powerquery


【解决方案1】:

鉴于您的文本数据行,假设您有几行数据,并且您可能在数据中有任何“分数”,我将在 PQ 中将其更改为数字:¼, @ 987654326@,¾.

在下面的代码中,进行多次替换:

  • 将文本字符串转换为列表
  • List.ReplaceMatchingItems 允许在一行代码中用不同的替换项替换多个不同的项目。
  • 我们还将您在数字和分数之间的space 替换为null
  • 然后将列表组合回文本字符串,并将其转换为数字。
  • 如果您的小数是包含空格的较长字符串的一部分,您需要确保只在正确的位置插入空值。

来源
M 代码

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WOrRXSUfJTOHQHiBlqgDhAbGxwqF9SrE60UpGMI6OkglElTlElaGBUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t]),
    typed = Table.TransformColumnTypes(Source, List.Transform(Table.ColumnNames(Source), each {_, Text.Type})),

//Replace all values
    colXformOps = List.Transform(Table.ColumnNames(typed), (cn)=>{cn, each Number.FromText(
                            Text.Combine(
                                List.ReplaceMatchingItems(
                                    Text.ToList(_),{{"¼",".25"},{"½",".5"},{"¾",".75"},{" ",null}})
                )),Number.Type}),
    replTbl = Table.TransformColumns(typed, colXformOps)
                
in
  replTbl

结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多