Forum Discussion
Text Manipulation using DAX
- 5 years ago
With your current model. It should be able to deal with any combination of contiguous and non-contiguous blocks of items:
MeasureV2 = VAR itemsT_ = CALCULATETABLE ( DISTINCT ( Table1[item] ), ALL ( Table1[description] ) ) VAR rankedT_ = ADDCOLUMNS ( itemsT_, "@index", RANKX ( itemsT_, [item],, ASC ) ) VAR aux_ = CONCATENATEX ( rankedT_, [item], "|", [@index], ASC ) VAR minIndex_ = 1 VAR maxIndex_ = COUNTROWS ( rankedT_ ) VAR res_ = CONCATENATEX ( rankedT_, VAR last_ = PATHITEM ( aux_, [@index] - 1, INTEGER ) VAR isBlockStart_ = last_ < ( [item] - 1 ) || [@index] = minIndex_ VAR next_ = PATHITEM ( aux_, [@index] + 1, INTEGER ) VAR isBlockEnd_ = ( next_ > ( [item] + 1 ) ) || [@index] = maxIndex_ RETURN IF ( isBlockStart_ && NOT isBlockEnd_, [item] & "-", IF ( isBlockEnd_, [item] & "," ) ), , [@index], ASC ) RETURN SELECTEDVALUE ( Table1[job] ) & "/" & IF ( RIGHT ( res_, 1 ) = ",", LEFT ( res_, LEN ( res_ ) - 1 ), res_ )I'm sure it can be coded more elegantly but I haven't had time to polish it yet
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- 5 years ago
The measure:
1. Gets the list of items
2. Ranks them to get them sorted in ascending order
3. Builds a string we can use PATHITEM on, since it simplifies the access to the ranked table
4. For each row in the ranked (sorted table), it checks the previous and next row to see if it's the beginning and/or end of a block.
5. Builds the final string, removing the unwanted "," at the end (this can be done earlier too)
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
See if this works for the third measure. First, the model:
Next, the measure:
Job/ Item =
VAR SelJob = SELECTEDVALUE('Dim Job'[job]) & "/ "
VAR _Item = CONCATENATEX(VALUES('DataTable'[item]), 'DataTable'[item], "-")
RETURN
SelJob & _Item
and the resulting table:
- mussaenda5 years agoCommunity Champion
Hi PaulDBrown ,
Thank you so much for the solution!
Just a question,
Is there a way that for week 3, it is 1200662/5, 7 instead of 5-7?
Because item 6 is not selected.
Thank youuuu