DAX - PowerBi - 严格匹配数组中的子集字符串并为其赋值
DAX - PowerBi - Match subset string strictly from array and assign value to it
Column =
VAR _1 =
ADDCOLUMNS ( 'digital_competences_q3', "new", SUBSTITUTE ( digital_competences_q3[q3_a], ";", "|" ) )
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _3 =
ADDCOLUMNS (
_2,
"score", MAXX ( FILTER ( 'lookup', EARLIER ( [_txt] ) = 'lookup'[Column1] ), 'lookup'[score] )
)
RETURN
CALCULATE (
MAXX (
ADDCOLUMNS (
'digital_competences_q3',
"score", SUMX ( FILTER ( _3, EARLIER ( digital_competences_q3[q3_a] ) = [q3_a] ), [score] )
),
[score]
)
)
从 @smpa01 如此慷慨地提供的代码中移出,用户可以 select 此数组中的任何选项:Computers with Windows operating system ;Computers with MAC operating system;Phones with Android operating system;Phones with iOS operating system;Tablets;
独立选项是:
- 装有 Windows 操作系统的计算机
- 具有 MAC 操作系统的计算机
- 装有 Android 操作系统的手机
- 装有 iOS 操作系统的手机
- 平板电脑
在用户 select 选择(可以是多个)之后,创建的数组将包含由“;”分隔的选项
主 table 包含包含数组 selected 的列
查找 table 具有分配给每个选项的值 (2)。
如果所有选项都 selected 总和是 20 而不是 10。
所以问题是,它是否匹配查找 table column1 中的整个值?还是基于常用词?正如我们所看到的,单个 IOS 值得到了正确的评分。
Column =
VAR _1 =
ADDCOLUMNS (
'digital_competences_q3',
"new", SUBSTITUTE ( digital_competences_q3[q3_a], ";", "|" )
)
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _3 =
ADDCOLUMNS (
_2,
"score",
MAXX (
FILTER ( '_lookup', EARLIER ( [_txt] ) = '_lookup'[Column1] ),
'_lookup'[score]
)
)
VAR _4 =
CALCULATE ( COUNTX ( digital_competences_q3, digital_competences_q3[q3_a] ) )
VAR _5 =
CALCULATE (
MAXX (
ADDCOLUMNS (
'digital_competences_q3',
"score",
SUMX (
FILTER ( _3, EARLIER ( digital_competences_q3[q3_a] ) = [q3_a] ),
[score]
)
),
[score]
)
)
RETURN
DIVIDE ( _5, _4 )
编辑
Column =
VAR _1 =
ADDCOLUMNS ( 'digital_competences_q3', "new", SUBSTITUTE ( digital_competences_q3[q3_a], ";", "|" ) )
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _3 =
ADDCOLUMNS (
_2,
"score", MAXX ( FILTER ( '_lookup', EARLIER ( [_txt] ) = '_lookup'[Column1] ), '_lookup'[score] )
)
VAR _4 = CALCULATE(COUNT(digital_competences_q3[q3_a]),ALLEXCEPT(digital_competences_q3,digital_competences_q3[q3_a]))
VAR _5 =
CALCULATE (
MAXX (
ADDCOLUMNS (
'digital_competences_q3',
"score", SUMX ( FILTER ( _3, EARLIER ( digital_competences_q3[q3_a] ) = [q3_a] ), [score] )
),
[score]
)
)
RETURN DIVIDE(_5,_4)
Column =
VAR _1 =
ADDCOLUMNS ( 'digital_competences_q3', "new", SUBSTITUTE ( digital_competences_q3[q3_a], ";", "|" ) )
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _3 =
ADDCOLUMNS (
_2,
"score", MAXX ( FILTER ( 'lookup', EARLIER ( [_txt] ) = 'lookup'[Column1] ), 'lookup'[score] )
)
RETURN
CALCULATE (
MAXX (
ADDCOLUMNS (
'digital_competences_q3',
"score", SUMX ( FILTER ( _3, EARLIER ( digital_competences_q3[q3_a] ) = [q3_a] ), [score] )
),
[score]
)
)
从 @smpa01 如此慷慨地提供的代码中移出,用户可以 select 此数组中的任何选项:Computers with Windows operating system ;Computers with MAC operating system;Phones with Android operating system;Phones with iOS operating system;Tablets;
独立选项是:
- 装有 Windows 操作系统的计算机
- 具有 MAC 操作系统的计算机
- 装有 Android 操作系统的手机
- 装有 iOS 操作系统的手机
- 平板电脑
在用户 select 选择(可以是多个)之后,创建的数组将包含由“;”分隔的选项
主 table 包含包含数组 selected 的列 查找 table 具有分配给每个选项的值 (2)。
如果所有选项都 selected 总和是 20 而不是 10。
所以问题是,它是否匹配查找 table column1 中的整个值?还是基于常用词?正如我们所看到的,单个 IOS 值得到了正确的评分。
Column =
VAR _1 =
ADDCOLUMNS (
'digital_competences_q3',
"new", SUBSTITUTE ( digital_competences_q3[q3_a], ";", "|" )
)
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _3 =
ADDCOLUMNS (
_2,
"score",
MAXX (
FILTER ( '_lookup', EARLIER ( [_txt] ) = '_lookup'[Column1] ),
'_lookup'[score]
)
)
VAR _4 =
CALCULATE ( COUNTX ( digital_competences_q3, digital_competences_q3[q3_a] ) )
VAR _5 =
CALCULATE (
MAXX (
ADDCOLUMNS (
'digital_competences_q3',
"score",
SUMX (
FILTER ( _3, EARLIER ( digital_competences_q3[q3_a] ) = [q3_a] ),
[score]
)
),
[score]
)
)
RETURN
DIVIDE ( _5, _4 )
编辑
Column =
VAR _1 =
ADDCOLUMNS ( 'digital_competences_q3', "new", SUBSTITUTE ( digital_competences_q3[q3_a], ";", "|" ) )
VAR _2 =
GENERATE (
_1,
ADDCOLUMNS (
GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
"_txt", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
)
)
VAR _3 =
ADDCOLUMNS (
_2,
"score", MAXX ( FILTER ( '_lookup', EARLIER ( [_txt] ) = '_lookup'[Column1] ), '_lookup'[score] )
)
VAR _4 = CALCULATE(COUNT(digital_competences_q3[q3_a]),ALLEXCEPT(digital_competences_q3,digital_competences_q3[q3_a]))
VAR _5 =
CALCULATE (
MAXX (
ADDCOLUMNS (
'digital_competences_q3',
"score", SUMX ( FILTER ( _3, EARLIER ( digital_competences_q3[q3_a] ) = [q3_a] ), [score] )
),
[score]
)
)
RETURN DIVIDE(_5,_4)