首页 > 解决方案 > (Excel) 函数根据条件从表中返回特定值

问题描述

我有以下数据:

store   location   mass   target
1       1 (Ams)    45     ?
2       5 (Ber)    500    ?
3       8 (Mar)    1003   ?

在最后一列目标中,我想从表中获取一个值:

              location 
 mass range    1       5     8 
 0 - 350       3       4     5
 > 351         6       7     8

因此,目标列应包含前三行中的值 3、7、8。

我尝试使用函数 INDEX() 但没有成功。如果有人知道如何在 R 或 PowerBI 中执行此操作,那也会对我有所帮助。谢谢!

在 R 中,该示例可通过以下方式重现:

structure(list(Store = 1:3, Location = structure(c(2L, 3L, 1L
), .Label = c("08-Mar", "1 Ams", "5 Ber"), class = "factor"), 
Mass = c(1000L, 800L, 500L)), class = "data.frame", row.names = c(NA, 
                                                                  -3L))

structure(list(X = structure(1:2, .Label = c("0 - 350", "351 - 1000"
), class = "factor"), X1 = c(3L, 6L), X5 = c(4L, 7L), X8 = c(5L, 
8L)), class = "data.frame", row.names = c(NA, -2L))

标签: rexcelpowerbi

解决方案


改革你的表2然后你可以使用INDEXMATCH功能如下

在此处输入图像描述


推荐阅读