Extracting English Names from Other Language Text Using DAX in Power BI

 Extracting English Names from Other Language Text Using DAX in Power BI

Dax Formula:

EnglishName =
VAR TextToSearch = 'YourTableName'[YourColumnName]
VAR EnglishChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
VAR NameStart = MINX(
    FILTER(
        ADDCOLUMNS(
            GENERATESERIES(1, LEN(TextToSearch), 1),
            "Character", MID(TextToSearch, [Value], 1)
        ),
        CONTAINSSTRING(EnglishChars, [Character])
    ),
    [Value]
)
VAR NameEnd = MAXX(
    FILTER(
        ADDCOLUMNS(
            GENERATESERIES(1, LEN(TextToSearch), 1),
            "Character", MID(TextToSearch, [Value], 1)
        ),
        CONTAINSSTRING(EnglishChars, [Character])
    ),
    [Value]
)
RETURN MID(TextToSearch, NameStart, NameEnd - NameStart + 1)

Explanation:

VAR TextToSearch = 'YourTableName'[YourColumnName]:

This line creates a variable named TextToSearch and assigns the value of the column 'YourTableName'[YourColumnName] to it. It stores the Arabic text you want to process.

VAR EnglishChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":

This line creates a variable named EnglishChars and assigns a string containing all English alphabet characters (both lowercase and uppercase) to it.

VAR NameStart = MINX(...):

This line creates a variable named NameStart. It uses the MINX function to find the minimum position of an English character in the text.
The FILTER function is used to filter characters from the generated series that belong to the English alphabet.
ADDCOLUMNS is used to add a column named "Character" to the generated series, which contains each character from the text.
CONTAINSSTRING filters only English characters, and MINX finds the minimum position.

VAR NameEnd = MAXX(...):

Similar to NameStart, this line creates a variable named NameEnd to find the maximum position of an English character in the text.

RETURN MID(...):

This line uses the MID function to extract the substring from the original text (TextToSearch).
It starts from the position NameStart and ends at the position NameEnd, effectively extracting the English name from the Other Language text.

Remember to replace 'YourTableName' with the name of your table and 'YourColumnName' with the name of the column containing the Arabic text. This DAX function is designed to find and extract English names from the Arabic text.

Feel free to ask any questions about Power BI. I am here to help you.

Happy Learning! 😊





Comments

Popular posts from this blog

Create Calendar Table in Power BI using DAX Function

Calculate Sales for Last Year Month to date

CONTAINSTRING DAX