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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Count Text in Columns

hello..

 

I have 40 columns. 

Results #1Results #2Results #3Results #Results #4Results #5ABFGPONNot availableLight Green
ABFNOT availableABFABFABFLight Green4  

1

 

I need a forumla to give the number of times it sees the text "ABF" and then one for another column "GPON" so on and so fourth. 

I am going to take these values, then total these in my visual. 

 

I am having a hard time getting the text counted in the columns per row. 

The columns in bold are the totals for each choice I am trying to create Power Bi help 04.20.png

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

HI @Anonymous 
The only way I could think of to unpivot the table using DAX is by hard coding the 40 columns. However, Power Query does it the same way, the only difference is that it generates the code automatically for you but in DAX you need to write it yourself.
I understand the disaster you went through when attempting to unpivot using Power Query therefore, please keep a backup copy before trying this with DAX. In general DAX is faster than Power Query and this code contains only two functions, UNION and SELECTCOLUMNS which are the fastest functions in DAX. Yet this might consume a significant amount of execution time for your big data to be processed but it is unlikely to crash.
The code is a repetition of a SELECTCOLUMNS statement (highlighted in green) that you need to copy and paste 40 times. Only the ones highlighted in red are the ones that you need to edit. Once you do that it would be easy to sum and count based on any filters you wish. (Please provide more details about the desired results and perhaps provide sample data to work with. Have a great day.

1.png

Ticketing Upivoted = 
UNION (
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "ABF", "Value", Ticketing[ABF]
    ),
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "GPON", "Value", Ticketing[GPON]
    ),
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "Not availabl", "Value", Ticketing[Not available]
    ),
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "Light Green", "Value", Ticketing[Light Green]
    )
)

View solution in original post

6 REPLIES 6
tamerj1
Community Champion
Community Champion

HI @Anonymous 
The only way I could think of to unpivot the table using DAX is by hard coding the 40 columns. However, Power Query does it the same way, the only difference is that it generates the code automatically for you but in DAX you need to write it yourself.
I understand the disaster you went through when attempting to unpivot using Power Query therefore, please keep a backup copy before trying this with DAX. In general DAX is faster than Power Query and this code contains only two functions, UNION and SELECTCOLUMNS which are the fastest functions in DAX. Yet this might consume a significant amount of execution time for your big data to be processed but it is unlikely to crash.
The code is a repetition of a SELECTCOLUMNS statement (highlighted in green) that you need to copy and paste 40 times. Only the ones highlighted in red are the ones that you need to edit. Once you do that it would be easy to sum and count based on any filters you wish. (Please provide more details about the desired results and perhaps provide sample data to work with. Have a great day.

1.png

Ticketing Upivoted = 
UNION (
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "ABF", "Value", Ticketing[ABF]
    ),
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "GPON", "Value", Ticketing[GPON]
    ),
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "Not availabl", "Value", Ticketing[Not available]
    ),
    SELECTCOLUMNS ( 
        Ticketing, 
        "Result", Ticketing[Results #1], "Result 2", Ticketing[Results #2], "Result 3", Ticketing[Results #3], "Result 4", Ticketing[Results #4], "Result 5", Ticketing[Results #5], "Result#", Ticketing[Results #], "Attribute", "Light Green", "Value", Ticketing[Light Green]
    )
)
Anonymous
Not applicable

I ended up being able to unpiviot the columns because of you 

But that after I caused your file to crash. Sorry for that again. 

Anonymous
Not applicable

You may not remember me... but I have posted about this before. THANK YOU!!!! 

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

I'd suggest to unpivot your table in Power Query. For this, go into Power Query, mark all the columns and click on Unpivot Columns:

tomfox_0-1650476683635.png

 

You should end up with a much longer table than this, but with the same structure:

 

tomfox_1-1650476742333.png

 

After you can create a measure like CALCULATE ( COUNT ( 'table'[Value] ), 'table'[Value] = "ABF" ) in DAX.

 

Would this work out for you? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

I get an error when I unpivot the columns. On attribute and value

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.