Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I'm having trouble finding an efficient way of setting the following command, and as new Power BI user with limited M and DAX experience, not sure how to best go about this.
In short, I'd like to create a new column of string values, based on length of string in another column.
More specifically, in my original column (LocationTag), I have acronyms for locations.
The locations are either 3 or 4+ length character acronyms.
I'd like to have a new column with information based on the length of the string in my original column.
LocationTag | New column |
ABCD | Away |
BCDEF | Away |
OSS | Home |
OMA | Home |
Manual replace values in the GUI is not an option as I have hundreds of different types of location tags. I'd also like to avoid searching/typing specific text and assigning it a new text (in the new column). I need to create the new column based on length of text string in the original column (LocationTag).... does Replace.Value based on character string length exist?
My thinking is something related to this:
if string is 3 characters in LocationTag
then, "Home"
if string is equal to or more than 4 characters
then, "Away"
Thank you very much for your help!
Solved! Go to Solution.
Hi @veronica_zappp ,
The function used is the same as the one provided by @rsbin , which is to return the length of a given string. Need a judgment condition has been added to this.
result =
IF (
LEN ( 'Table'[LocationTag] ) < 3,
"error",
IF (
LEN ( 'Table'[LocationTag] ) = 3,
"home",
IF ( LEN ( 'Table'[LocationTag] ) > 3, "away" )
)
)
If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @veronica_zappp ,
The function used is the same as the one provided by @rsbin , which is to return the length of a given string. Need a judgment condition has been added to this.
result =
IF (
LEN ( 'Table'[LocationTag] ) < 3,
"error",
IF (
LEN ( 'Table'[LocationTag] ) = 3,
"home",
IF ( LEN ( 'Table'[LocationTag] ) > 3, "away" )
)
)
If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Using DAX, create a new Calculated Column. You are on the right track with your IF statement, but
I now prefer using the SWITCH function instead of the usual IF Statement.
You just need to be made aware of the LEN function.
NewColumn = SWITCH(
TRUE(),
LEN(YourTable[LocationTag]) = 3, "Home",
"Away")
This is my source for the comprehensive list of DAX functions:
https://docs.microsoft.com/en-us/dax/
Hope this helps.
Regards,
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |