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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors