Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
HI,
I am having an use case where I need to use SUBSTITUTE function. SUBSTITUTE should have dynamic occurance - which means, someties it changes 1st occurance , sometimes 2nd etc.
Summarizing the problem:
Solved! Go to Solution.
I think you're just not handling the case when there are no occurrences. This works for me:
Where
Last Occurance =
VAR _text = SELECTEDVALUE ( 'table'[Text] )
VAR _ToPath = SUBSTITUTE ( _text, "X", "|" )
VAR _Result = PATHLENGTH ( _ToPath ) - 1
RETURN
_Result
@AlexisOlson Awesome solution. Thanks for that!
I think you're just not handling the case when there are no occurrences. This works for me:
Where
Last Occurance =
VAR _text = SELECTEDVALUE ( 'table'[Text] )
VAR _ToPath = SUBSTITUTE ( _text, "X", "|" )
VAR _Result = PATHLENGTH ( _ToPath ) - 1
RETURN
_Result
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 38 | |
| 36 | |
| 33 | |
| 32 | |
| 28 |
| User | Count |
|---|---|
| 129 | |
| 88 | |
| 79 | |
| 68 | |
| 63 |