Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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 

  • 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.

    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]
        )
    )

6 Replies

  • tackytechtom's avatar
    tackytechtom
    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:

     

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

     

     

    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/

     

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

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

  • tamerj1's avatar
    tamerj1
    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.

    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's avatar
      Anonymous
      Not applicable

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

    • Anonymous's avatar
      Anonymous
      Not applicable

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

      • tamerj1's avatar
        tamerj1
        Community Champion

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