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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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.

R_P_0-1594952379914.png

 

Cheers,

16 REPLIES 16
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
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
Not applicable

Hi @Anonymous 

I want to add one more column in the concatenate e.g.

R_P_0-1595207809870.png

 

What's wrong with using REPT() ?

Anonymous
Not applicable

@lbendlin I need a delimter also to seperate the text

Include the delimiter in the call to REPT and throw away the last character of the result.

Anonymous
Not applicable

@lbendlin

 

CONCATENATEX does it all for you automatically, so why bother?


Best
D

Because it's fun, and an opportunity to test a function I didn't even know until very recently.

Anonymous
Not applicable

Yeah... It's also fun to kill a bird with a cannon 🙂

Best
D
AntrikshSharma
Community Champion
Community Champion

This looks like a job for Power Query and not DAX
Anonymous
Not applicable

Hi @AntrikshSharma 

 

A power Query solution will work too.

 

Cheers,

Unfortunately I am not capable enough in PQ, you can post your question here were PQ champs hangout:

https://community.powerbi.com/t5/Power-Query/bd-p/power-bi-services
Anonymous
Not applicable

@AntrikshSharma  Thanks!!

amitchandak
Super User
Super User

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

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
Not applicable

@amitchandak 

Does the above answer help you to understand the problem?

 

Cheers,

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors