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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
uk-roberto92
Frequent Visitor

DAX: If () with Group_by on (id) and conditions on other columns

Hi, I have a table of the form:

 

id  case  status
0    1       xx
0    555     yy
0    125     zz
2     87     yy
2     nn     xx

And I am trying to code something like the below:

for every id if 1 case has status xx and 1 case has status yy, THEN I want yy = xx

So the resulting table would be

id   case    status
0     1        xx
0     555      **xx**
0     125      zz
2     87       **xx**
2     nn       xx

 

I tried with 

Column=
IF (
    MAXX (
        FILTER (
            'Table',
            'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[status] = "xx"
        ),
        'Table'[status]
    ) = "",
    "",
    "xx"
)

but that doesn't work as it would transform all the *statuses* per *id* into -xx-.

 

Any help on this?

Thanks

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can create a calculated column like

Actual Status = IF( 'Table'[status] = "yy",
    VAR NumXX = CALCULATE(
        COUNTROWS( 'Table' ),
        ALLEXCEPT( 'Table', 'Table'[id]),
        'Table'[status] = "xx"
    )
    VAR NumYY = CALCULATE(
        COUNTROWS( 'Table' ),
        ALLEXCEPT( 'Table', 'Table'[id] ),
        'Table'[status] = "yy"
    )
    VAR Result = IF( NumXX = 1 && NumYY = 1, "xx", 'Table'[status] )
    RETURN Result,
    'Table'[status]
)

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

You can create a calculated column like

Actual Status = IF( 'Table'[status] = "yy",
    VAR NumXX = CALCULATE(
        COUNTROWS( 'Table' ),
        ALLEXCEPT( 'Table', 'Table'[id]),
        'Table'[status] = "xx"
    )
    VAR NumYY = CALCULATE(
        COUNTROWS( 'Table' ),
        ALLEXCEPT( 'Table', 'Table'[id] ),
        'Table'[status] = "yy"
    )
    VAR Result = IF( NumXX = 1 && NumYY = 1, "xx", 'Table'[status] )
    RETURN Result,
    'Table'[status]
)

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.