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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

DAX for grouping value

Hi, 

 

I have been trying to create a dax code that would regroup my data like below:

IDStatusFREQ IDStatus
101173150Compliant1 101173150Compliant
101173547Compliant2 101173547Compliant
101173547First2 101173547Compliant
101173549Compliant2 101173549Not Compliant
101173549Not Compliant2 101173549Not Compliant
101173571Not Compliant1 101173571Not Compliant
101173572Not Compliant2 101173572Not Compliant
101173572Last2 101173572Not Compliant
101173702Compliant1 101173702Compliant
101173706Compliant2 101173706Not Compliant
101173706Not Compliant2 101173706Not Compliant
101173815Compliant2 101173815Not Compliant
101173815Not Compliant2 101173815Not Compliant
101173847Not Compliant1 101173847Not Compliant
101173868Compliant3 101173868Not Compliant
101173868Not Compliant3 101173868Not Compliant
101173868First3 101173868Not Compliant

 

 

The scenario is that when there are multiple values for one ID I would prioritise "not compliant" status if "not compliant" is not there i would take "compliant" over "first" or "last" status.

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

There is a small error in the expression provided by @amitchandakPlease modify it as follows:

New column = 
VAR _nc =
    COUNTX (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Not Compliant" ),
        [ID]
    )
VAR _c =
    COUNTX (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Compliant" ),
        [ID]
    )
VAR _f =
    COUNTX (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "First" ),
        [ID]
    )
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( _nc ) ), "Not Compliant",
        NOT ( ISBLANK ( _c ) ), "Compliant",
        NOT ( ISBLANK ( _f ) ), "First",
        "Last"
    )

 

Or try this:

Column = 
VAR _nc =
    COUNTROWS (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Not Compliant" )
    )
VAR _c =
    COUNTROWS (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Compliant" )
    )
VAR _f =
    COUNTROWS ( 
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "First" ) )
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( _nc ) ), "Not Compliant",
        NOT ( ISBLANK ( _c ) ), "Compliant",
        NOT ( ISBLANK ( _f ) ), "First",
        "Last"
    )
Measure =
VAR _nc =
    COUNTROWS (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [ID] = MAX ( [ID] )
                && [Status] = "Not Compliant"
        )
    )
VAR _c =
    COUNTROWS (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [ID] = MAX ( [ID] )
                && [Status] = "Compliant"
        )
    )
VAR _f =
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [ID] = MAX ( [ID] ) && [Status] = "First" )
    )
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( _nc ) ), "Not Compliant",
        NOT ( ISBLANK ( _c ) ), "Compliant",
        NOT ( ISBLANK ( _f ) ), "First",
        "Last"
    )

COLUMN.JPGMEASURE.JPG

 

 

Best Regards,

Icey

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @Anonymous ,

 

There is a small error in the expression provided by @amitchandakPlease modify it as follows:

New column = 
VAR _nc =
    COUNTX (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Not Compliant" ),
        [ID]
    )
VAR _c =
    COUNTX (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Compliant" ),
        [ID]
    )
VAR _f =
    COUNTX (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "First" ),
        [ID]
    )
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( _nc ) ), "Not Compliant",
        NOT ( ISBLANK ( _c ) ), "Compliant",
        NOT ( ISBLANK ( _f ) ), "First",
        "Last"
    )

 

Or try this:

Column = 
VAR _nc =
    COUNTROWS (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Not Compliant" )
    )
VAR _c =
    COUNTROWS (
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "Compliant" )
    )
VAR _f =
    COUNTROWS ( 
        FILTER ( 'Table', [ID] = EARLIER ( [ID] ) && [Status] = "First" ) )
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( _nc ) ), "Not Compliant",
        NOT ( ISBLANK ( _c ) ), "Compliant",
        NOT ( ISBLANK ( _f ) ), "First",
        "Last"
    )
Measure =
VAR _nc =
    COUNTROWS (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [ID] = MAX ( [ID] )
                && [Status] = "Not Compliant"
        )
    )
VAR _c =
    COUNTROWS (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [ID] = MAX ( [ID] )
                && [Status] = "Compliant"
        )
    )
VAR _f =
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [ID] = MAX ( [ID] ) && [Status] = "First" )
    )
RETURN
    SWITCH (
        TRUE (),
        NOT ( ISBLANK ( _nc ) ), "Not Compliant",
        NOT ( ISBLANK ( _c ) ), "Compliant",
        NOT ( ISBLANK ( _f ) ), "First",
        "Last"
    )

COLUMN.JPGMEASURE.JPG

 

 

Best Regards,

Icey

 

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

amitchandak
Super User
Super User

@Anonymous , a New column like

 

New column =
var _nc = countx(filter(table, [ID] =earlier([ID]), [Status] ="Not Compliant"),[ID])
var _c = countx(filter(table, [ID] =earlier([ID]), [Status] ="Compliant"),[ID])
var _f = countx(filter(table, [ID] =earlier([ID]), [Status] ="First"),[ID])
return
Switch( true(),
not(isblank(_nc)) , "Not Compliant",
not(isblank(_c)) , "Compliant",
not(isblank(_f)) , "First",
"Last"
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
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!

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