我有一个包含 ordernumber、productionarea 和 productionstart、data1、data2、data3 的数据集。 数据集以未排序的方式交付。数据集看起来像:
订单号 | 生产区域 | 生产日期 | 数据1 | 数据2 | 数据3 |
---|---|---|---|---|---|
订单1 | 区域1 | 12/01/2023 | 5 | 3 | 9 |
订单13 | 面积5 | 14/01/2023 | 6 | 2 | 4 |
订单11 | 区域3 | 19/01/2023 | 7 | 9 | 5 |
订单12 | 区域1 | 14/01/2023 | 8 | 8 | 6 |
订单16 | 区域3 | 01/01/2023 | 9 | 7 | 7 |
订单13 | 区域1 | 13/01/2023 | 8 | 6 | 8 |
我想要的是添加一列(data4)的解决方案,其中包含下一个订单的data2的结果。或者根据生产日期确定来自同一生产区域的下一个订单号的解决方案。因此,对于 order1,我需要来自 order13 的结果(这是基于开始日期的下一个结果)。通过查找功能,我可以从不同的列中检索值,但我需要先获得正确的下一个订单号。
所以在这种情况下:order1, area1, 12/01/2023 需要一个新列,其值来自 data2 from order13,这是基于日期的 area1 中的下一个订单。
我尝试创建一个新表(参考)并按生产日期对其进行排序,然后使用基于生产单位的过滤器。但是我没有得到正确的结果;
我开始于:
VAR CurrentOrderNumber = dataset[ordernumber]
VAR CurrentArea = dataset[productionarea]
RETURN
CALCULATE(MIN('dataset'[ordernumber]), FILTER('dataset','dataset'[ordernumber] > CurrentOrderNumber && ('dataset'[productionarea]=CurrentArea)))
它给出了 order12(area1) 而不是 order13(area1) 的结果,如果我按 productionDate 排序,那么你可以看到 order13 是下一行,而不是 order12.
想要的结果: |订单号 |产区 |生产日期 |数据1 |数据2 |数据3 |数据4 | | ---------- | -------------- | -------------- | ----- | ----- | ----- | ----- | |订单1 |区域1 | 2023 年 1 月 12 日 | 5 | 3 | 9 | 6 | |订单13 |区域5 | 2023 年 1 月 14 日 | 6 | 2 | 4 | | |订单11 |区域3 | 2023 年 1 月 19 日 | 7 | 9 | 5 | | |订单12 |区域1 | 2023 年 1 月 14 日 | 8 | 8 | 6 | | |订单16 |区域3 | 2023 年 1 月 1 日 | 9 | 7 | 7 | 2 | |订单13 |区域1 | 2023 年 1 月 13 日 | 8 | 6 | 8 | 9 |
或
订单号 | 生产区域 | 生产日期 | 数据1 | 数据2 | 数据3 | 下一个订单 |
---|---|---|---|---|---|---|
订单1 | 区域1 | 12/01/2023 | 5 | 3 | 9 | 订单13 |
订单13 | 面积5 | 14/01/2023 | 6 | 2 | 4 | |
订单11 | 区域3 | 19/01/2023 | 7 | 9 | 5 | |
订单12 | 区域1 | 14/01/2023 | 8 | 8 | 6 | |
订单16 | 区域3 | 01/01/2023 | 9 | 7 | 7 | 订单11 |
订单13 | 区域1 | 13/01/2023 | 8 | 6 | 8 | 订单12 |
计算列:
=
VAR ThisProductArea = Table1[ProductionArea]
VAR ThisProductDate = Table1[ProductionDate]
VAR NextProdDate =
CALCULATE (
MIN ( Table1[ProductionDate] ),
FILTER (
Table1,
Table1[ProductionArea] = ThisProductArea
&& Table1[ProductionDate] > ThisProductDate
)
)
RETURN
CALCULATE (
MIN ( Table1[Ordernumber] ),
FILTER (
Table1,
Table1[ProductionArea] = ThisProductArea
&& Table1[ProductionDate] = NextProdDate
)
)