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
Hi mussaenda
Please explain the logic behind the expected result rather than leaving it up to the reader's guess. Otherwise we're all wasting precious time.
Try this. You'll probably have to tweak it a bit but it should get you close:
Measure =
VAR items_ =
CALCULATETABLE (
DISTINCT ( 'Sheet1 (Job/Item)'[item] ),
ALL ( 'Sheet1 (Job/Item)'[description] )
)
RETURN
SELECTEDVALUE ( 'Sheet1 (Job/Item)'[job] ) & "/"
& CONCATENATEX ( items_, [item], "-", [item], ASC )
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
- mussaenda5 years agoCommunity Champion
Hi AlB ,
Sorry, I thought I have explained it on the expected output.
Assuming that the selected values from the item filter are 1, 2, 3, 5, and 7.
1. Week 1 has only 2 items and both were selected, that's why the output is job 1200662/1-2.
2. Week 2 has 2 items also but only one is selected (item3), that's why the output is job 1200662/3.
3. Week 3 has 3 items but NOT all were selected, that's why the output is job 1200662/5, 7.
They are just duplicating because of the description. which is totally okay.
- lbendlin5 years agoSuper User
If you accept 1,2 for the first scenario rather than 1-2 then all scenarios can be covered with a single concatenatex statement.
- mussaenda5 years agoCommunity Champion
I wanted to.
But the issue here is,
sometimes for one week, the are 25 items.
It is not acceptable to show 1, 2, 3, 4, 5, ... 25
That's why they required 1-25.
Is there other way to do it?