The lack of options for FIND
or SEARCH
to search from the end of the string makes this quite tricky.
You can use:
Env = TRIM(RIGHT(SUBSTITUTE('AWS Reservations'[Account], " ", REPT(" ", LEN('AWS Reservations'[Account]))), LEN('AWS Reservations'[Account])))
Or break it down for better understanding:
Env =
VAR string_length = LEN('AWS Reservations'[Account])
RETURN
TRIM(
RIGHT(
SUBSTITUTE(
'AWS Reservations'[Account],
" ",
REPT(" ", string_length)
),
string_length
)
)
Take lm-sample prod
as an example.
First, we use REPT(" ", string_length)
to create a string of
" "
which has the same length as the value
lm-sample prod
.
Then, we substitute all the occurrences of " " with this extra long
" "
and the string will become
lm-sample prod
After that, we'll be comfortable getting the substring of string_length
from the right, i.e.
" prod"
Finally, we trim the result to get what we want, prod
.
Results:

Reference