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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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

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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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