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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
mouzicanat1
Regular Visitor

Counting same contact per row when mixed in with multiple contacts

Hello!

 

I have the following example:

TaskContacts
1John
2John, Andy, Stacy
3

Andy, Stacy

4Stacy, John

 

I want to pull data that shows me number of tasks each contact was assigned to.
Example: John = 3, Andy = 2, Stacy = 3.

I thought this could easily be combined when filtering, but it still separates into different groups: John | John, Andy, Stacy | Stacy, John.

 

Any ideas here? Thank you!

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@mouzicanat1  for whatever reason you can't do what @AlexisOlson  is suggesting, DAX can still rescue.

 

You need a slicer table first

Slicer =
VAR _1 =
    ADDCOLUMNS ( tbl, "new", SUBSTITUTE ( tbl[Contacts], ",", "|" ) )
VAR _2 =
    GENERATE (
        _1,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "persons", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
        )
    )
RETURN
    SUMMARIZE ( _2, [persons] )

which will give you this

smpa01_0-1638222574455.png

then you can write a measure like this

Measure =
VAR _1 =
    ADDCOLUMNS ( tbl, "new", SUBSTITUTE ( tbl[Contacts], ",", "|" ) )
VAR _2 =
    GENERATE (
        _1,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "persons", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
        )
    )
VAR _3 =
    COUNTX (
        FILTER ( _2, [persons] = SELECTEDVALUE ( Slicer[persons] ) ),
        [persons]
    )
RETURN
    _3

 

smpa01_1-1638222668805.png

 

If you want the Total to be reconciled too

Measure2 =
VAR _1 =
    ADDCOLUMNS ( tbl, "new", SUBSTITUTE ( tbl[Contacts], ",", "|" ) )
VAR _2 =
    GENERATE (
        _1,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "persons2", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
        )
    )
VAR _3 =
    SUMX (
        ADDCOLUMNS (
            Slicer,
            "ct", COUNTX ( FILTER ( _2, [persons2] = EARLIER ( [persons] ) ), [persons2] )
        ),
        [ct]
    )
RETURN
    _3

 

smpa01_2-1638222967055.png

pbix is attached

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

13 REPLIES 13
smpa01
Super User
Super User

@mouzicanat1  for whatever reason you can't do what @AlexisOlson  is suggesting, DAX can still rescue.

 

You need a slicer table first

Slicer =
VAR _1 =
    ADDCOLUMNS ( tbl, "new", SUBSTITUTE ( tbl[Contacts], ",", "|" ) )
VAR _2 =
    GENERATE (
        _1,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "persons", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
        )
    )
RETURN
    SUMMARIZE ( _2, [persons] )

which will give you this

smpa01_0-1638222574455.png

then you can write a measure like this

Measure =
VAR _1 =
    ADDCOLUMNS ( tbl, "new", SUBSTITUTE ( tbl[Contacts], ",", "|" ) )
VAR _2 =
    GENERATE (
        _1,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "persons", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
        )
    )
VAR _3 =
    COUNTX (
        FILTER ( _2, [persons] = SELECTEDVALUE ( Slicer[persons] ) ),
        [persons]
    )
RETURN
    _3

 

smpa01_1-1638222668805.png

 

If you want the Total to be reconciled too

Measure2 =
VAR _1 =
    ADDCOLUMNS ( tbl, "new", SUBSTITUTE ( tbl[Contacts], ",", "|" ) )
VAR _2 =
    GENERATE (
        _1,
        ADDCOLUMNS (
            GENERATESERIES ( 1, PATHLENGTH ( [new] ) ),
            "persons2", TRIM ( PATHITEM ( [new], [Value], TEXT ) )
        )
    )
VAR _3 =
    SUMX (
        ADDCOLUMNS (
            Slicer,
            "ct", COUNTX ( FILTER ( _2, [persons2] = EARLIER ( [persons] ) ), [persons2] )
        ),
        [ct]
    )
RETURN
    _3

 

smpa01_2-1638222967055.png

pbix is attached

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

oo! I will try that. Thank you!! 
I was also considering expanding to new rows, but was unable to find that option. I only found forums from years ago, so maybe that feature is gone?

I was able to replicate this. Thank you!

Nice. 🙂

 

This is a fun nut to crack but I'd offer this characterization to anyone thinking about implementing it in any serious work product:

AlexisOlson_0-1638224374810.png

Always nice to have more options and see different solutions though regardless of their practicality.

hahaha that meme entirely applies to my workplace.

AlexisOlson
Super User
Super User

I'd strongly recommend expanding the table in the query editor to have one row per Contact rather than trying to work with rows containing combined names.

Thank you for the response!

I figured to do that, but it's a long list of contacts, which also often changes. But I guess I will do that for now.

Power BI can handle lots of rows much more easily than picking apart fewer rows.

 

Changing often shouldn't be a problem provided you're splitting the rows automatically in the query editor rather than doing it manually.

Hello again!

 

I did just that, but as the data was updating over time. The new rows wouldn't split automatically. I would have to repeat the splitting again.
Is there a feature I'm missing here to always have it auto-split when seeing a row that has a "comma"?

If the splitting is a step in your query to load the data, I don't know why new rows wouldn't split. Maybe you need to move that step later in your query? Hard to say without seeing the query.

Hi Alexis,

Really appreciate the quick response!

Looks like I need to re-enter the split. Additionally, I need to re-enter the value replacement steps (some contacts are entered in different formats, so I need to replace the values). Let me know if more information is needed from me.

mouzicanat1_1-1642791930539.png

 

It seems odd to me that you need to repeat these steps so many times. Is your table getting wider? If so, I'd strongly recommend unpivoting some of your columns if it makes sense to do so.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors