首页 > 解决方案 > 用于检查 COG 是否在边界框中的 PowerQuery 公式

问题描述

我正在尝试定义对象的齿轮在哪个框中。例如,我有一个带有 COG (1.2, 1.5, 0.3) (x, y, z) 的项目和一个框列表:

箱数 Z 低 Z高 Y 离开 X前 X 船尾
1 0 3 -5 0 5 0
2 0 3 0 5 5 0

在此示例中,该项目位于框 2 中。我现在的解决方案是使用 Sumifs,如果 COG 低于/高于边界值,则检查每个边界,因为框没有重叠。

大多数数据都是用 powerquery 加载的,但我不能让这个 sumifs 语句在 powerquery 中工作,我必须将数据加载到 excel 并添加 sumifs 语句,如果我想在 Power BI 中加载它,这将不起作用。否则我必须打开 excel,在那里刷新并让计算运行,保存,打开 PBI 并在那里刷新。

是否可以使用 sumifs 或仅使用 Power BI 的其他解决方案来做出此声明?

标签: excelpowerbipowerquerysumifs

解决方案


您可以只比较x,y,z参数并输出通过测试的框号列表。

例如:(作为函数)

(x as number, y as number, z as number) =>
let
    Box = Table.FromRecords({
        [Box Number=1, Z Low=0, Z High=3,Y Left=-5,Y Right=0,X Front=5,X Aft=0],
        [Box Number=2,Z Low = 0, Z High=3, Y Left=0, Y Right=5,X Front=5,X Aft=0]
    }),

    typeIt = Table.TransformColumnTypes(
            Box, List.Transform(Table.ColumnNames(Box), each {_,Int64.Type})
    ),
    inOut = Table.AddColumn(typeIt,"ckBox", each 
        x >= [X Aft] and x<= [X Front] and 
        y >= [Y Left] and y <= [Y Right] and 
        z >= [Z Low] and z <= [Z High]
    ),
    boxNum = Table.SelectRows(inOut,each [ckBox] = true)
in 
    boxNum[Box Number]

推荐阅读