Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Print the column values multiple times using DAX

Hi there,

 

I am trying to print values for a specific column. for example the column name is ABC and it is occured 18 times for a key, the output needs to be as per below.

 

Cheers,

16 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

     

    // Assumption is that you've got a table T
    // where the structure is more or less this:
    // Key	|	Column
    // ----------------
    // 1	|	ABC
    // 1	| 	ABC
    // 2	|	XYZ
    // 2	|	XYZ
    // 2	|	XYZ
    // ...
    // From your sample it looks like a key
    // can only have one distinct value in
    // the Column column.
    
    [Output] =
    IF( 
    	// make sure that only one Key is
    	// visible in the current context
    	// and it's filtered directly.
    	HASONEFILTER( T[Key] ),
    
    	// The below will only work correctly
    	// if the assumption above is in force.
    	// Otherwise, SELECTEDVALUE will return
    	// BLANK() and you'll end up with a string
    	// of delimiters only or just an empty
    	// string.
    	var __numOfVals = COUNTROWS( T )
    	var __columnVal = SELECTEDVALUE( T[Column] )
    	var __ouput =
    		CONCATENATEX(
    			GENERATESERIES(1, __numOfVals, 1),
    			__columnVal,
    			":|"
    		)
    	return
    		__output
    )

     

     

    And, of course, [Output] is a MEASURE, not a calc column.

     

    Best

    D

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Anonymous The below measure works well.

      I want to add one more column which is a unique number for each "ABC" value.

       

      Cheers,

      Rutika

  • Anonymous , Can you explain the logic of output, not able to connect.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Amit,

       

      Basically I want to concatenate the output the number of times it appears as per the column headers.

      Hopefully this explains !

       

      Cheers,

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        amitchandak 

        Does the above answer help you to understand the problem?

         

        Cheers,