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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
saadghojaria
Frequent Visitor

Labelling data into category with Conditional Column

Hi, 
I have the data which I want to tag with conditional column called Rev Type by categories called RevA or RevB. Here is my Column DAX code  which performs :
- to check if the user name starts with bp of any of the row of specific eq category then the Rev column will be RevA or else no username starts with bp will be RevB. 

- exclude all rows with other than current status as effective

Code:
Rev Type =
IF(
    CALCULATE(
        COUNTROWS(
            FILTER(
                ALL('Z'),
                LEFT('Z'[Username], 2) = "bp"
            )
        ),
        ALLEXCEPT('Z', 'Z'[Eq])
    ) > 0,
    "RevA",
    "RevB"
)
Current output : 
Rev Type (current)EqUsernameCurrent status
RevAAavalEffective
RevAAbp02Effective
RevAAavalEffective
RevAAavalEffective
RevACmnilEffective
RevACrferEffective
RevACvtEffective
RevACmnilEffective
RevACmnilEffective
RevAA Draft
RevAB Draft
RevAD Draft
RevAC Draft
RevABavalCirculation
RevADmnilCirculation
RevACvtCirculation

 

Expected Output

Revision Type (expected)EqUsernameCurrent status
RevAAavalEffective
RevAAbp02Effective
RevAAavalEffective
RevAAavalEffective
RevBCmnilEffective
RevBCrferEffective
RevBCvtEffective
RevBCmnilEffective
RevBCmnilEffective
N/AA Draft
N/AB Draft
N/AD Draft
N/AC Draft
N/ABavalCirculation
N/ADmnilCirculation
N/ACvtCirculation
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you PhilipTreacy

Hi, @saadghojaria 

I used the following example data:

vjianpengmsft_0-1727332145129.png

 

You can use the following DAX expression to correctly calculate your Rev Type

Column = IF (
    'Table'[Current status] = "Effective",
    VAR _table =
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER ( 'Table', 'Table'[Current status] = "Effective" ),
                'Table'[Eq],
                'Table'[Username]
            ),
            "Isfit", SEARCH ( "bp", 'Table'[Username], 1, 0 )
        )
    VAR _eq =
        SELECTCOLUMNS ( FILTER ( _table, [Isfit] = 1 ), 'Table'[Eq] )
    VAR _table2 =
        ADDCOLUMNS (
            ALL ( 'Table' ),
            "Res", SWITCH ( TRUE (), 'Table'[Eq] IN _eq, "Rev_A", "RevB" )
        )
    VAR _current_eq = 'Table'[Eq]
    RETURN
        MAXX ( FILTER ( _table2, 'Table'[Eq] = _current_eq ), [Res] ),
    "N/A"
)

The results are as follows:

vjianpengmsft_1-1727332183221.png

I've provided the PBIX file used this time below.

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thank you PhilipTreacy

Hi, @saadghojaria 

I used the following example data:

vjianpengmsft_0-1727332145129.png

 

You can use the following DAX expression to correctly calculate your Rev Type

Column = IF (
    'Table'[Current status] = "Effective",
    VAR _table =
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER ( 'Table', 'Table'[Current status] = "Effective" ),
                'Table'[Eq],
                'Table'[Username]
            ),
            "Isfit", SEARCH ( "bp", 'Table'[Username], 1, 0 )
        )
    VAR _eq =
        SELECTCOLUMNS ( FILTER ( _table, [Isfit] = 1 ), 'Table'[Eq] )
    VAR _table2 =
        ADDCOLUMNS (
            ALL ( 'Table' ),
            "Res", SWITCH ( TRUE (), 'Table'[Eq] IN _eq, "Rev_A", "RevB" )
        )
    VAR _current_eq = 'Table'[Eq]
    RETURN
        MAXX ( FILTER ( _table2, 'Table'[Eq] = _current_eq ), [Res] ),
    "N/A"
)

The results are as follows:

vjianpengmsft_1-1727332183221.png

I've provided the PBIX file used this time below.

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PhilipTreacy
Super User
Super User

@saadghojaria 

 

It's not really clear what you want, can you please provide an example of the desired result you seek?

 

The code you have provided, what is that for?  The first section of code is seraching for the string "bp". the second piece of code is lookign for "bp" at the start of the string.

 

Please clarify.

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Phil,

Thanks for looking into this, please check now if it makes more sense.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.