简体   繁体   English

Power BI 中的索引和聚合 FUNCTION

[英]INDEX and AGGREGATE FUNCTION in Power BI

I have a two tables are data and report.我有两个表,分别是数据和报告。

In data table the following columns are Size A, Size B and Size C, Type and Rank.在数据表中,以下列为尺寸 A、尺寸 B 和尺寸 C、类型和等级。

In data table I created rank for each type based on the sizes.在数据表中,我根据大小为每种类型创建了排名。 The purpose of the rank column were multiple matches for same size in this case the rank column will help to decide exact type were match more than one. rank 列的目的是针对相同大小进行多次匹配,在这种情况下,rank 列将有助于确定匹配多个的确切类型。

In report table the following columns are Size A, Size B and Size C.在报告表中,以下列为尺寸 A、尺寸 B 和尺寸 C。

In both table the Size A, Size B and Size C columns are common/relationship.在这两个表中,尺寸 A、尺寸 B 和尺寸 C 列是共同/关系。

I am trying find out the appropriate type according to the Size A, Size B and Size C from data table into report table.我正在尝试根据从数据表到报告表的尺寸 A、尺寸 B 和尺寸 C 找出合适的类型。

Data:数据:

TYPE类型 SIZEA尺码 SIZEB大小 SIZEC尺寸 RANK
A6 A6 420 420 600 600 440 440 11.00 11.00
A4 A4 640 640 600 600 480 480 9.00 9.00
A5 A5 890 890 1100 1100 1330 1330 2.00 2.00
A6 A6 1335 1335 1100 1100 2350 2350 1.00 1.00
A7 A7 890 890 1100 1100 390 390 5.00 5.00
A8 A8 890 890 1100 1100 530 530 3.00 3.00
A9 A9 670 670 1100 1100 540 540 4.00 4.00
A10 A10 670 670 1100 1100 440 440 6.00 6.00
A11 A11 320 320 1100 1100 440 440 10.00 10.00
A12 A12 600 600 400 400 400 400 12.00 12.00
A13 A13 800 800 600 600 400 400 8.00 8.00
A14 A14 1000 1000 600 600 500 500 7.00 7.00

Report:报告:

SIZEA尺码 SIZEB大小 SIZEC尺寸 DESIRED RESULT-TYPE期望的结果类型
400 400 300 300 140 140 A12 A12
A12 A12
250 250 250 250 160 160 A12 A12
600 600 400 400 285 285 A12 A12
400 400 300 300 150 150 A12 A12
280 280 230 230 170 170 A12 A12
320 320 320 320 320 320 A12 A12
320 320 320 320 320 320 A12 A12
600 600 400 400 140 140 A12 A12
400 400 300 300 140 140 A12 A12
400 400 300 300 140 140 A12 A12
370 370 320 320 340 340 A12 A12
320 320 240 240 250 250 A12 A12
300 300 200 200 90 90 A12 A12
400 400 290 290 140 140 A12 A12

I am applying following formula in report table in order to get the appropriate type according to the Size A, Size B and Size C我在报告表中应用以下公式,以便根据尺寸 A、尺寸 B 和尺寸 C 获得适当的类型

=INDEX(DATA!$D$2:$D$16,AGGREGATE(15,6,(ROW(DATA!$H$2:$H$16)-1)/(DATA!$H$2:$H$16=1/(1/MAX(((DATA!$E$2:$E$16>=$B3)*(DATA!$F$2:$F$16>=$A3)+(DATA!$E$2:$E$16>=$A3)*(DATA!$F$2:$F$16>=$B3)>0)*(DATA!$G$2:$G$16>=$C3)*DATA!$H$2:$H$16))),1)) 

在此处输入图像描述

在此处输入图像描述

How can I apply the same logic in Power BI?如何在 Power BI 中应用相同的逻辑? Any advise please.请有任何建议。

I am looking for new calculate column options.我正在寻找新的计算列选项。 Herewith share the Excel file for your reference特此分享Excel文件供大家参考

https://www.dropbox.com/scl/fi/iq0gteeyazrg79q7a4tb1/AUTO-MODIFY-REQ.xlsx?dl=0&rlkey=nyyerjsg7if2dz30z9iqo6kdc https://www.dropbox.com/scl/fi/iq0gteeyazrg79q7a4tb1/AUTO-MODIFY-REQ.xlsx?dl=0&rlkey=nyyerjsg7if2dz30z9iqo6kdc

Here is another formula that will return the same result as per your current formula, although it is still a long formula, but more easily to understand:这是另一个公式,它将根据您当前的公式返回相同的结果,虽然它仍然是一个很长的公式,但更容易理解:

=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L3,0,
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0))
*$H$2:$H$13),$H$2:$H$13,0),1)

在此处输入图像描述

So I will break it down to explain how do it working:所以我将分解它来解释它是如何工作的:

Part 1 : This if formula is checking comparison of Size C , if your data is lower than than table, the value for the Type will be zero therefore will not be considered at all because zero times any amount will be zero第 1 部分:如果公式正在检查Size C的比较,如果您的数据低于表,则Type的值将为零,因此根本不会考虑,因为zero times any amount都将为零

(IF($G$2:$G$13<$L3,0

Part 2 : This part is will first checking comparison of Size A vs Size B , if lower than table than return 0 and apply for other comparison, at then end using If at the beginning to reset the value so than the final value will be 0 or 1第 2 部分:这部分将首先检查Size A vs Size B比较,如果小于表,则返回 0 并申请其他比较,然后在结束时使用If at the beginningreset值,以便最终值为 0或 1

IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0)

Part 3 : From the value you calculate, if 0 times any ranking will be zero, so from none zero ranking such as 12 or 9, it will get the max value from the list, most of them are 12第 3 部分:从你计算的值来看,如果 0 次任何排名都是零,所以从非零排名,例如 12 或 9,它将从列表中获取最大值,其中大多数是12

Max((.....)*$H$2:$H$13)

Part 4 : Index Match - Finally it is same as your formula first part, but you are using Index row which make it difficult to understand第 4 部分:索引匹配 - 最后它与您的公式第一部分相同,但您使用的是Index row ,这使得它难以理解

INDEX($D$2:$D$13,MATCH(Max(...))

A shorter version of your formula by removing unnecessary portion:通过删除不必要的部分来简化公式:

=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L4,0,
IF(($E$2:$E$13>=$K4)*($F$2:$F$13>=$J4)+($E$2:$E$13>=$J4)*($F$2:$F$13>=$K4)>0,1,0))*$H$2:$H$13),
$H$2:$H$13,0),1)

You can add a colum to your report table like:您可以向报告表中添加一个列,例如:

Desired = LOOKUPVALUE(DataR[TYPE],DataR[RANK], MAXX(FILTER(DataR, DataR[SIZEA] >= ReportR[SIZEA] && DataR[SIZEB] >= ReportR[SIZEB] && DataR[SIZEC] >= ReportR[SIZEC]), DataR[RANK]))

It first filters the table to find the row where the sizes are more or equal to the report row, selects the rank and then does a lookup to the type.它首先过滤表以查找大小大于或等于报表行的行,选择排名,然后查找类型。

Result:结果: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM