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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
mwjansen
Frequent Visitor

Data grouping with multiple entries in cells.

In 'Table' table there is a column [Body Part]. The data comes from user entries, and they are allowed to select multiple entries. 

ie Hand, Ankle, Back (the entry form inserts the commas/spaces). 

 

I want to be able to group (or count) each individual body part for use in a visual. 

 

            Body Part

Row     Hand (r), Hand (l), Shoulder (l)

            Ankle (r)

            Leg (l), Hand (r)

            Hand (l), Neck, Back

            Back, Shoulder (r)

 

In this example, I want to be able to show a count of Hand(4), Ankle (1), Leg(1), Neck(1), Back(2), Shoulder(2). 

Not concerned with L or R for this count. 

I tried data grouping, but once I put the first entry into a group (for Hand), I cannot use it in another group (for Shoulder), and thus the Shoulder count would be off. 

 

Is there another way? Some kind of measure I could write? 

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

In Power Query, split data of that column into rows and remove the information within brackets.  Now you should be able to use this measure

Measure = countrows(Data)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@mwjansen are you adding it as a column or a measure? 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@mwjansen create a new table for body parts and use the following DAX. See attached file for reference:

 

Body Parts Count = 
VAR __Count = 
SUMX ( 
    'Table',
    VAR __CurrentRow =  SUBSTITUTE ( 'Table'[Row], "," , "|" )
    VAR __CurrentRowTotalBodyParts = PATHLENGTH ( __CurrentRow )
    VAR __CurrentBodyPartsTable = 
        SELECTCOLUMNS ( 
            ADDCOLUMNS ( 
                GENERATESERIES ( 1, __CurrentRowTotalBodyParts ), 
                "Current Part", PATHITEM ( __CurrentRow, [Value] ) 
            ), 
            "Current Part", [Current Part] 
        )
    VAR __BodyPartsFound =  
    FILTER ( 
        CROSSJOIN ( __CurrentBodyPartsTable, 'Body Parts' ),
        CONTAINSSTRING ( [Current Part], [Body Part] )
    )
    RETURN
       COUNTROWS ( __BodyPartsFound )
    
)
RETURN 
    __Count 



        

 

Result:

 

parry2k_0-1741730130576.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k I believe I made all the subs in the DAX. 

"The expression specified in the query is not a valid table expression"

Body Parts Count = 
VAR __Count = 
SUMX ( 
    'OR Incident Log',
    VAR __CurrentRow =  SUBSTITUTE ( 'OR Incident Log'[BODY PART], "," , "|" )
    VAR __CurrentRowTotalBodyParts = PATHLENGTH ( __CurrentRow )
    VAR __CurrentBodyPartsTable = 
        SELECTCOLUMNS ( 
            ADDCOLUMNS ( 
                GENERATESERIES ( 1, __CurrentRowTotalBodyParts ), 
                "Current Part", PATHITEM ( __CurrentRow, [Value] ) 
            ), 
            "Current Part", [Current Part] 
        )
    VAR __BodyPartsFound =  
    FILTER ( 
        CROSSJOIN ( __CurrentBodyPartsTable, 'Anatomy' ),
        CONTAINSSTRING ( [Current Part], [Body Part] )
    )
    RETURN
       COUNTROWS ( __BodyPartsFound )
    
)
RETURN 
    __Count 

 

"Current Part" is highlighted red 

parry2k
Super User
Super User

@mwjansen how many approx. rows you have in the transaction tables?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k 645 rows. 

Also, I want to exclude the (r) and (l) identifiers in the cells. 

parry2k
Super User
Super User

@mwjansen you need to create a table with all the body parts that you want to count. once that table is available, you can iterate thru each row value of that table and check with transaction table to get the count.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k 

I think I understand what you've written, but have no idea how to get started. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.