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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
karlamaddox1
Helper I
Helper I

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
Super User
Super User

HI @karlamaddox1 
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
Super User
Super User

HI @karlamaddox1 
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]
    )
)

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. 

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

tackytechtom
Super User
Super User

Hi @karlamaddox1 ,

 

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 

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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