Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
wsMac78AZ
Frequent Visitor

Count number of matched words between two columns

Hi,

I have 4 columns in my table and I would like to count the number of alphabets in column B that match column D and then produce the result in column E. 

 

For example, in ticket 1001, all four alphabets matched the alphabets in column D and the total count is "4".

 

In ticket 1002 only the alphabet "K" matched that in column D hence the count is "1".

 

I would appreciate any help in solving this problem with PowerBI.

 

Thanking you in advance.

 

wsMac78AZ_1-1655216170890.png

 

 

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @wsMac78AZ,

You can create a calculated column with PATH and GENERATESERIES function to expand the text items, then you can simply use INTERSECT function to compare two lists of items and get the counts.

Item Count =
VAR _pathA =
    SUBSTITUTE ( 'Table'[Order], ",", "|" )
VAR listA =
    SELECTCOLUMNS (
        GENERATESERIES ( 1, PATHLENGTH ( _pathA ), 1 ),
        "Item", PATHITEM ( _pathA, [Value] )
    )
VAR _pathB =
    SUBSTITUTE ( 'Table'[Selection], ",", "|" )
VAR listB =
    SELECTCOLUMNS (
        GENERATESERIES ( 1, PATHLENGTH ( _pathB ), 1 ),
        "Item", PATHITEM ( _pathB, [Value] )
    )
RETURN
    COUNTROWS ( DISTINCT ( INTERSECT ( listA, listB ) ) )

6.png

Reference links:

PATHLENGTH function (DAX) - DAX | Microsoft Docs

PATHITEM function (DAX) - DAX | Microsoft Docs

GENERATESERIES function - DAX | Microsoft Docs

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @wsMac78AZ,

You can create a calculated column with PATH and GENERATESERIES function to expand the text items, then you can simply use INTERSECT function to compare two lists of items and get the counts.

Item Count =
VAR _pathA =
    SUBSTITUTE ( 'Table'[Order], ",", "|" )
VAR listA =
    SELECTCOLUMNS (
        GENERATESERIES ( 1, PATHLENGTH ( _pathA ), 1 ),
        "Item", PATHITEM ( _pathA, [Value] )
    )
VAR _pathB =
    SUBSTITUTE ( 'Table'[Selection], ",", "|" )
VAR listB =
    SELECTCOLUMNS (
        GENERATESERIES ( 1, PATHLENGTH ( _pathB ), 1 ),
        "Item", PATHITEM ( _pathB, [Value] )
    )
RETURN
    COUNTROWS ( DISTINCT ( INTERSECT ( listA, listB ) ) )

6.png

Reference links:

PATHLENGTH function (DAX) - DAX | Microsoft Docs

PATHITEM function (DAX) - DAX | Microsoft Docs

GENERATESERIES function - DAX | Microsoft Docs

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Xiaoxin Sheng,

 

Many thanks for your assistance. It works for me.

 

Regards,

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.