Forum Discussion
Dynamic Text Using List Separated by Commas and or Before Last Value
- 3 years ago
Thanks! This helped lead me down the right path. I still had to do some tweaking, but this works for me based on how it's set up in my dashboard.
ProjectSelection_Exits = VAR SelectedProj = VALUES(ExitsPH_HUD[RecodePgmType]) VAR NumberOfSelectedProj = COUNTROWS (SelectedProj) VAR AllButLastProj = TOPN(NumberOfSelectedProj - 1, SelectedProj) VAR LastSelectedProj = EXCEPT(SelectedProj, AllButLastProj) RETURN IF(NumberOfSelectedProj = 3 || NumberOfSelectedProj = 4, CONCATENATEX(AllButLastProj, ExitsPH_HUD[RecodePgmType], ", ") & ", or " & LastSelectedProj, IF(NumberOfSelectedProj = 2, CONCATENATEX(AllButLastProj, ExitsPH_HUD[RecodePgmType], ", ") & " or " & LastSelectedProj, IF(NumberOfSelectedProj = 1, LastSelectedProj, "all service types")))
Hi heatherkw, here is the way to create a measure that dynamically contains multiple selected string values:
Dynamic Title Measure = CONCATENATEX( Projects, Projects[Project Title], "," )
Original solution has been proposed by Matt Allington in this community post.
Hi, thanks, this I can already do. The issue is that when there are more than 2 in the list, I want to have "and" before the last selection in the list as this is going to be in a sentence, so needs to be grammatically correct. An example would be "Emergency Shelter, Transitional Housing, and Rapid Re-Housing." I know it's possible because I found a solution sometime last year when I was working on something else but I just can't find it anymore.
- Sergii243 years agoSuper User
Well, we can modify the same measure:
Dynamic Title Measure = VAR _NumOfProjectsSelected = COUNTROWS( Projects ) VAR _AllSelectedProjectsExceptLastOne = //this 1 column table will have all projects except 1 selected, so we'll use CONCATENATEX later for this one SELECTCOLUMNS( //SELECTCOLUMNS is added in case you have multiple columns in Projects table, which are not necessary in this measure TOPN( _NumOfProjectsSelected - 1, Projects, Projects[Project Title], ASC //important that here you use a value different from the one in _LastSelectedProject ), "@Project Title", [Project Title] ) VAR _LastSelectedProject = //this 1 column table will always have only 1 row SELECTCOLUMNS( TOPN( 1, Projects, Projects[Project Title], DESC //important that here you use a value different from the one in _AllSelectedProjectsExceptLastOne ), "@Project Title", [Project Title] ) RETURN IF( _NumOfProjectsSelected > 3, "More than 3 projects selected", IF( _NumOfProjectsSelected > 1, CONCATENATEX( _AllSelectedProjectsExceptLastOne, [@Project Title], ", " ) & " and " & _LastSelectedProject, _LastSelectedProject ) )
I hope it is what you've been looking for! 🙂- heatherkw3 years agoHelper I
Thanks! This helped lead me down the right path. I still had to do some tweaking, but this works for me based on how it's set up in my dashboard.
ProjectSelection_Exits = VAR SelectedProj = VALUES(ExitsPH_HUD[RecodePgmType]) VAR NumberOfSelectedProj = COUNTROWS (SelectedProj) VAR AllButLastProj = TOPN(NumberOfSelectedProj - 1, SelectedProj) VAR LastSelectedProj = EXCEPT(SelectedProj, AllButLastProj) RETURN IF(NumberOfSelectedProj = 3 || NumberOfSelectedProj = 4, CONCATENATEX(AllButLastProj, ExitsPH_HUD[RecodePgmType], ", ") & ", or " & LastSelectedProj, IF(NumberOfSelectedProj = 2, CONCATENATEX(AllButLastProj, ExitsPH_HUD[RecodePgmType], ", ") & " or " & LastSelectedProj, IF(NumberOfSelectedProj = 1, LastSelectedProj, "all service types")))