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
D_PBI
Post Patron
Post Patron

SUMMARIZE and CONCATENATEX with filtering (possibly need CONTAINS) - help?!

Hi,

I have the below DAX which works as expected:

Concatenate_Tags =
          SUMMARIZE(
                               patent_PATENTS,
                               patent_PATENTS[Reference Number],
                               "Tags", CONCATENATEX( VALUES( patent_PATENTS[Tag Name] ), patent_PATENTS[Tag Name], ", " )
                               )

 

What I would like to do is to ONLY include in the concatenation Tag Name containing "BRC" and Tag Name not equal to "no BRC".

 

How do I achieve this? 

I thinking I need to REMOVE rows from the patent_PATENTS table where the column Tag Name does not contain "BRC" and equals "no BRC". Below is my attempt in doing this:

Concatenate_Tags =

          SUMMARIZE(
                               FILTER(
                                          patent_PATENTS,
                                         AND(
                                                  CONTAINS( patent_PATENTS , patent_PATENTS[Tag Name], "BRC" ),
                                                  patent_PATENTS[Tag Name] <> "no BRC"
                                                 )
                                         ),
                              patent_PATENTS[Reference Number],
                              "Tags", CONCATENATEX( VALUES( patent_PATENTS[Tag Name] ), patent_PATENTS[Tag Name], ", " )
)

 

However, this is not working. Please can advise help?
Thanks.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

This may work:

ADDCOLUMNS(
	VALUES( patent_PATENTS[Reference Number] ),
	"Tags",
		var __tags =
			CALCULATETABLE(
				VALUES( patent_PATENTS[Tag Name] ),
				patent_PATENTS[Tag Name] <> "no BRC",
				filter(
					ALL( patent_PATENTS[Tag Name] ),
					CONTAINSSTRING(
						patent_PATENTS[Tag Name],
						"BRC"
					)
				)
			)
		var __concat =
			CONCATENATEX(
				__tags,
				patent_PATENTS[Tag Name],
				", "
			)
		return
			__concat
)

But I don't quite get it... Are you creating a measure or you want a query? It looks like a query to me...

 

By the way, please do not use SUMMARIZE to do any calculations inside it. It's DANGEROUS and may return incorrect results without you even realizing that. Instead, use it only to get the unique combinations of values in rows.

 

Best
D

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

This may work:

ADDCOLUMNS(
	VALUES( patent_PATENTS[Reference Number] ),
	"Tags",
		var __tags =
			CALCULATETABLE(
				VALUES( patent_PATENTS[Tag Name] ),
				patent_PATENTS[Tag Name] <> "no BRC",
				filter(
					ALL( patent_PATENTS[Tag Name] ),
					CONTAINSSTRING(
						patent_PATENTS[Tag Name],
						"BRC"
					)
				)
			)
		var __concat =
			CONCATENATEX(
				__tags,
				patent_PATENTS[Tag Name],
				", "
			)
		return
			__concat
)

But I don't quite get it... Are you creating a measure or you want a query? It looks like a query to me...

 

By the way, please do not use SUMMARIZE to do any calculations inside it. It's DANGEROUS and may return incorrect results without you even realizing that. Instead, use it only to get the unique combinations of values in rows.

 

Best
D

@Pragati11  - thanks for your contribution. Unfortunately, in following your example it returned nothing (empty column). I see the difference in your DAX to mine but it didn't work. Note, I had to remove the () bracket pairing from each filter line as without doing so it was returning the error 'Operator or expression '()' is not supported in this context'.

 

@Anonymous  - thanks for your contribution. It was spot on and worked how I needed.

To answer your question, assuming when you say measure you mean doing the piece of work using a DAX measure, and when you say query you are referring to completing the task using Power Query (is this what you mean??) - if you are suggesting I need a PQ query then yes, using Power Query, I would typically create an additional column in the table, that has the reference number/tag name, and concatenate the tag name there. I agree that this task being a modelling task it should be done in PQ.

However, I wanted to complete this requirement using DAX. I am strong at PQ but weaker at DAX. By requesting what I did, I have now seen some new stuff in DAX.
I placed your DAX code in a new table and then joined the new table's Reference Number field to the same field in patent_PATENTS table.

 

Kudos to both of you as efforts to my requirement, whether successful or not, are appreciated.

Thanks.

Anonymous
Not applicable

Well... No. When I say "measure," I mean a measure. When I say "query," I mean a query in DAX, which is a construct that starts with EVALUATE. Queries in DAX are the same concept as queries in MDX. PQ is a totally different animal still.

Queries are executed from a client that wants to pull out data from a tabular cube. It's like SQL to tables. For instance, the DAX function SUMMARIZECOLUMNS can only be used in queries (not in measures).

Best
D

In that case, a DAX 'query' is what I required for this exercise. A 'measure', being a scalar value, wouldn't cater for my intention.

Thanks again. Most helpful 👍

Anonymous
Not applicable

Yeah. I was kind of surprised when I saw that the initial formula returned a table... I couldn't be a measure, yet there was no EVALUATE. But then it could have been a calculated table as well. It's always good to state what kind of object you're after....

Best
D
Pragati11
Super User
Super User

Hi @D_PBI ,

 

Modify your DAX to the following:

 

Concatenate_Tags =
          SUMMARIZE(

                               Filter(

                                         (patent_PATENTS, patent_PATENTS[Tag Name] <> "no BRC")

                                         &&  

                                         (CONTAINS( patent_PATENTS , patent_PATENTS[Tag Name], "BRC" ) == TRUE())

                                       ),
                               patent_PATENTS[Reference Number],
                               "Tags", CONCATENATEX( VALUES( patent_PATENTS[Tag Name] ), patent_PATENTS[Tag Name], ", " )
                               )

 

If this helps please give Kudos and mark it as a Solution! 🙂

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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