Forum Discussion
Dynamic column concatenating distinct values
- 6 years ago
Hi heatherl ,
I would used CONCATENEX, and SELECTEDVALUE
Concatenates the result of an expression evaluated for each row in a table.
Syntax
DAXCopyCONCATENATEX(<table>, <expression>, [delimiter])Parameters
Term Definitiontable The table containing the rows for which the expression will be evaluated. expression The expression to be evaluated for each row of the table. delimiter (optional) A separator to use during concatenation. Return value
A text string.
SELECTEDVALUE
- 12/09/2018
- 2 minutes to read
Returns the value when the context for columnName has been filtered down to one distinct value only. Otherwise returns alternateResult.
Syntax
DAXCopySELECTEDVALUE(<columnName>[, <alternateResult>])
Parameters
Term DefinitioncolumnName The name of an existing column, using standard DAX syntax. It cannot be an expression. alternateResult (Optional) The value returned when the context for columnName has been filtered down to zero or more than one distinct value. When not provided, the default value is BLANK(). Return value
The value when the context for columnName has been filtered down to one distinct value only. Else, alternateResult.
- 6 years ago
Hi Nathaniel_C , v-lili6-msft ,
Thanks to both of you for your help. I discovered that if I use my same code creating a measure instead of a custom column, then it works as desired.
EN Code(s) new = calculate(CONCATENATEX(values(WAGES[EN Code]),WAGES[EN Code],","))
So thank you for that!
I have another resulting issue but I will open a separate discussion for it. Thanks again!
Hi Nathaniel_C ,
Thanks for your assistance. Can you explain what the SELECTEDVALUE would be doing here? I'm not understanding what exactly what it does.
Based on your CONCATENATEX suggestion I did some more searching and put together this column.
test = calculate(CONCATENATEX(values(WAGES[EN Code]),WAGES[EN Code],","))
It works at getting the distinct values but it is working the same as my SQL column; when the wages filters are updated, the field still show all of the values even if they are no longer relevant.
Thanks
hi, heatherl
Sample data and expected output would help tremendously.
Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
For your case, I think you need to add the filter context in the formula.
test = calculate(CONCATENATEX(values(WAGES[EN Code]),WAGES[EN Code],",") ,<filter1>)
Best Regards,
Lin
- heatherl6 years agoFrequent Visitor
Hi Nathaniel_C , v-lili6-msft ,
Thanks to both of you for your help. I discovered that if I use my same code creating a measure instead of a custom column, then it works as desired.
EN Code(s) new = calculate(CONCATENATEX(values(WAGES[EN Code]),WAGES[EN Code],","))
So thank you for that!
I have another resulting issue but I will open a separate discussion for it. Thanks again!