Forum Discussion
Why is not Function SubstituteWithIndex() able to detect common columns?
Why is not Function SubstituteWithIndex() able to detect common columns between its operands that could be used for join?Please guide and prompt the reasons for such errors. Thank you
I follow the method of adding index columns, but I get an error:
SubstituteWithIndex() is not able to detect common columns between its operands that could be used for join.
However, if you add one more line of code, it will become a virtual table, and then add an index column to calculate the table,the result is correct result:
Please give me directions when it's convenient. Thank you
Hi yaowen
Thanks for reaching out to us.
>> Why is not Function SubstituteWithIndex() able to detect common columns between its operands that could be used for join?Please guide and prompt the reasons for such errors.
-
In my opinion, according to the definition of SubstituteWithIndex(), "it returns ...of the two tables supplied as arguments", so we need to pass 2 tables as arguments to it. In INDEX2, you defined a virtual table _Product, however, in INDEX1, there is only one table. So I guess that's why it's giving an error.
FYI: SUBSTITUTEWITHINDEX function (DAX) - DAX | Microsoft Docs
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
5 Replies
- yaowenFrequent Visitor
Such as: Performance optimization of powerbi maximum continuous element number algorithm.
The idea of the staggered element method is to stagger the original elements, and then calculate the start and end marks. Here, changing the vertical comparison to the horizontal comparison, which can greatly reduce the number of iterations. Therefore, the algorithm achieves significant performance improvement
VAR MyData = SELECTCOLUMNS( '10W' , "OrginIndex" , [Item] , "Value" , [Flag] ) VAR Add1 = ADDCOLUMNS( MyData , "Value2" , SELECTCOLUMNS( FILTER( MyData , [OrginIndex] = EARLIER( [OrginIndex] ) - 1 ) , "Value" , [Value] ) ) VAR Add1Filterd = FILTER( Add1 , [Value] + [Value2] = 1 ) VAR CreateBegin = ADDCOLUMNS( Add1Filterd , "BeginIndex" , IF( [Value] = 1 , [OrginIndex] ) ) VAR CreateEnd = ADDCOLUMNS( CreateBegin , "EndIndex" , IF( [Value2] = 1 , [OrginIndex] ) ) VAR CreateIndex = SUBSTITUTEWITHINDEX( CreateEnd , "Index" , SELECTCOLUMNS( CreateEnd , "OrginIndex" , [OrginIndex] ) , [OrginIndex] , ASC ) VAR AddAdd = ADDCOLUMNS( CreateIndex , "NewEndIndex" , SELECTCOLUMNS( FILTER( CreateIndex , [Index] = EARLIER( [Index] ) + 1 ) , "NewEndIndex" , [EndIndex] ) ) VAR AddAddFilterd = FILTER( AddAdd , ISBLANK( [EndIndex] ) ) RETURN MAXX( AddAddFilterd , [NewEndIndex] - [BeginIndex] )Among all kinds of optimization, adding index is a very common and immediate optimization method. DAX provides this function to select the future table for the user to add indexes, so I want to understand SUBSTITUTEWITHINDEX. Thank you!
- v-xiaotangCommunity Support
Hi yaowen
Thanks for reaching out to us.
>> Why is not Function SubstituteWithIndex() able to detect common columns between its operands that could be used for join?Please guide and prompt the reasons for such errors.
-
In my opinion, according to the definition of SubstituteWithIndex(), "it returns ...of the two tables supplied as arguments", so we need to pass 2 tables as arguments to it. In INDEX2, you defined a virtual table _Product, however, in INDEX1, there is only one table. So I guess that's why it's giving an error.
FYI: SUBSTITUTEWITHINDEX function (DAX) - DAX | Microsoft Docs
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.