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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
swalz
New Member

Conditionals Help

Looking for some assistance with understanding how to apply conditionals based on value naming conventions. We have a standard naming convention that needs to be followed with several variations as follows:

 

X-XXXX

X-XXXX-X

X-XXXX-XXXX

X-XXXX-XXXX-X

X-XXXX-XXXX-XXXX

etc.

 

A quick look at the values I'm dealing with is shown below where green highlight is good, red is bad.

 

swalz_0-1727976332807.png

 

What are the best and easiest ways to achieve within PowerBI?

 

Thanks!

 

Steve

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @swalz - you can achieve by creating a calculated column or measure in Power BI that applies a pattern-matching logic

 

rajendraongole1_0-1728020867761.png

 

IsValidName =
SWITCH(
    TRUE(),
    -- X-XXXX (Length = 6)
    LEN([NamingConvention]) = 6 && MID([NamingConvention], 2, 1) = "-", 1,
   
    -- X-XXXX-X (Length = 😎
    LEN([NamingConvention]) = 8 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-", 1,
   
    -- X-XXXX-XXXX (Length = 11)
    LEN([NamingConvention]) = 11 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-", 1,
   
    -- X-XXXX-XXXX-X (Length = 13)
    LEN([NamingConvention]) = 13 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-" && MID([NamingConvention], 12, 1) = "-", 1,
   
    -- X-XXXX-XXXX-XXXX (Length = 16)
    LEN([NamingConvention]) = 16 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-" && MID([NamingConvention], 12, 1) = "-", 1,
   
    -- If none of the patterns match
    0
)
 
i am using table chart in format pane to go the cell element apply the new column condition 1 for good and 0 for bad. i am using dark color you can choose your colors as per your request
 
rajendraongole1_2-1728021041788.png

 

 
rajendraongole1_1-1728020979134.png

 

Hope this helps.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi, @swalz 

Thanks for Ritaf1983 and rajendraongole1 reply. You can refer to their reply, or you can try the following way.

1. Add a new column to remove non-alphanumeric characters in Power Query

Text.Select([Column1], {"A".."Z", "a".."z"})

vyaningymsft_0-1728028371432.png

2. Write the following dax to create a calculate column

vyaningymsft_1-1728028566106.png

 

Format = 
VAR NameLength =
    LEN ( [Name] )
VAR FirstChar =
    LEFT ( [Name], 1 )
VAR RemainingChars =
    MID ( [Name], 2, NameLength - 1 )
VAR FormattedRemainingChars =
    CONCATENATEX (
        GENERATESERIES ( 1, LEN ( RemainingChars ), 4 ),
        MID ( RemainingChars, [Value], 4 ),
        "-"
    )
RETURN
    FirstChar & "-" & FormattedRemainingChars

 

Best Regards,
Yang

Community Support Team

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

rajendraongole1
Super User
Super User

Hi @swalz - you can achieve by creating a calculated column or measure in Power BI that applies a pattern-matching logic

 

rajendraongole1_0-1728020867761.png

 

IsValidName =
SWITCH(
    TRUE(),
    -- X-XXXX (Length = 6)
    LEN([NamingConvention]) = 6 && MID([NamingConvention], 2, 1) = "-", 1,
   
    -- X-XXXX-X (Length = 😎
    LEN([NamingConvention]) = 8 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-", 1,
   
    -- X-XXXX-XXXX (Length = 11)
    LEN([NamingConvention]) = 11 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-", 1,
   
    -- X-XXXX-XXXX-X (Length = 13)
    LEN([NamingConvention]) = 13 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-" && MID([NamingConvention], 12, 1) = "-", 1,
   
    -- X-XXXX-XXXX-XXXX (Length = 16)
    LEN([NamingConvention]) = 16 && MID([NamingConvention], 2, 1) = "-" && MID([NamingConvention], 7, 1) = "-" && MID([NamingConvention], 12, 1) = "-", 1,
   
    -- If none of the patterns match
    0
)
 
i am using table chart in format pane to go the cell element apply the new column condition 1 for good and 0 for bad. i am using dark color you can choose your colors as per your request
 
rajendraongole1_2-1728021041788.png

 

 
rajendraongole1_1-1728020979134.png

 

Hope this helps.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Ritaf1983
Super User
Super User

Hi @swalz 
What is the logic of the conditions of the wanted coloring?

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.