Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
NSBS
Helper I
Helper I

Differentiating Spaces Within a Code and Between a Code

Hi Experts,

 

Is there any way for us to differentiate the SPACES BETWEEN a codename and SPACES WITHIN a codename

 

Example:

In below Table, initially there is Code List and I want to create a new column to state the position of spaces whether it is in between or within

*Note: each codename will has '@' in it

 

Code ListSpace Position
ABC@ZZ, DEF@ZZspaces in between
ABC @zz, DEF@ZZspaces within and in between
ABC @zz,DEF@ZZspaces within
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NSBS 

 

Check this dax code for new column

Column =
VAR between =
FIND (
", ",
Codelist_space[Code List],
,
0
)
VAR within =
FIND (
" ",
SUBSTITUTE (
Codelist_space[Code List],
", ",
""
),
,
0
)
RETURN
IF (
between > 0
&& within > 0,
"spaces within and in between",
IF (
between > 0,
"spaces in between",
IF (
within > 0,
"spaces within"
)
)
)

 

If this post helps, Accept it as a solution

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi

 

use the following dax code to add a new column

Column =
VAR code1 =
LEFT (
Codelist_space[Code List],
FIND (
",",
Codelist_space[Code List],
,
0
) - 1
)
VAR code2 =
RIGHT (
Codelist_space[Code List],
LEN ( Codelist_space[Code List] )
- FIND (
",",
Codelist_space[Code List],
,
0
)
)
VAR between =
IF (
FIND (
" ",
code2,
,
0
) = 1,
1
)
VAR within =
IF (
FIND (
" ",
code1,
,
0
) > 0
|| FIND (
" ",
code2,
2,
0
) > 0,
1
)
RETURN
IF (
between = 1
&& within = 1,
"spaces within and in between",
IF (
between = 1,
"spaces in between",
IF (
within = 1,
"spaces within"
)
)
)

 

If this post helps, Accept it as a solution

Hi @Anonymous ,

 

Really appreciate your DAX code.

 

However my code list is not only limited for 2 codes per row. It might have 1 code or more than 2 codes.

Example: ajk@ZZ, yh W@@ZZ, GWW@ZZ

Is there any way we can differentiate the spaces is WITHIN or BETWEEN code

Anonymous
Not applicable

Hi @NSBS 

 

Check this dax code for new column

Column =
VAR between =
FIND (
", ",
Codelist_space[Code List],
,
0
)
VAR within =
FIND (
" ",
SUBSTITUTE (
Codelist_space[Code List],
", ",
""
),
,
0
)
RETURN
IF (
between > 0
&& within > 0,
"spaces within and in between",
IF (
between > 0,
"spaces in between",
IF (
within > 0,
"spaces within"
)
)
)

 

If this post helps, Accept it as a solution

Hi @Anonymous 

 

Currently I need the M code for this space detection as well. I already try create it but no output at all.
Kindly help on this matter.

 

Thank you.

Anonymous
Not applicable

hi @NSBS 

 

You can add a custom column with the code below

 

let
between = Text.Contains([Code List],", "),
within = Text.Contains(Text.Replace([Code List],", ",",")," ")
in
if between and within then "Space within and in between"
else if between then "Space in between"
else if within then "Space Within"
else "No space"

 

 

Hi @Anonymous ,

 

Thank you very much for your help. I can detect the spacing now.

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.