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
joyc0025
Frequent Visitor

Create a Measure to display most frequent category with conditions.

How can I create a DAX measure to display the most frequent non-compliance outcome for a given month on a card? The measure should exclude rows with "Y" in the compliance column and "NA" or 'Nil' in the non-compliance category column. In case of ties, the measure should use severity as the tiebreaker (Low, Medium, High - assume 1,2 3 if helps?).

 

Initially assumed it would be straightforward, I have spent hours experimenting with various approaches involving filters, calculated tables, addcolumns, summarize, and rankx functions. Now i'm just more confused and going in circles.


Table: Compliance

Table.jpg

 The desired outcome for March 2023, the card would display "Fraud".

 

Any assistance or guidance would be greatly appreciated. Thank you in advance.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1685176156513.png

 

 

Jihwan_Kim_0-1685176130247.png

 

 

Expected outcome measure: =
VAR _t =
    ADDCOLUMNS (
        FILTER (
            Compliance,
            Compliance[Compliance] <> "Y"
                && NOT ( Compliance[Non Compliance] IN { "NA", "Nil" } )
        ),
        "@tiebreaker",
            SWITCH (
                TRUE (),
                Compliance[Severity] = "High", 3,
                Compliance[Severity] = "Medium", 2,
                Compliance[Severity] = "Low", 1
            )
    )
VAR _grouptable =
    GROUPBY (
        _t,
        Compliance[Date],
        Compliance[Non Compliance],
        "@count", SUMX ( CURRENTGROUP (), 1 ),
        "@tiebreak", SUMX ( CURRENTGROUP (), [@tiebreaker] )
    )
VAR _highest =
    MAXX (
        ADDCOLUMNS ( _grouptable, "@value", [@count] * 10 + [@tiebreak] ),
        [@value]
    )
RETURN
    IF (
        HASONEVALUE ( Compliance[Date] ),
        CONCATENATEX (
            FILTER (
                ADDCOLUMNS ( _grouptable, "@value", [@count] * 10 + [@tiebreak] ),
                [@value] = _highest
            ),
            Compliance[Non Compliance],
            ", "
        )
    )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
joyc0025
Frequent Visitor

This solution is perfect, thank you so much 🙂

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1685176156513.png

 

 

Jihwan_Kim_0-1685176130247.png

 

 

Expected outcome measure: =
VAR _t =
    ADDCOLUMNS (
        FILTER (
            Compliance,
            Compliance[Compliance] <> "Y"
                && NOT ( Compliance[Non Compliance] IN { "NA", "Nil" } )
        ),
        "@tiebreaker",
            SWITCH (
                TRUE (),
                Compliance[Severity] = "High", 3,
                Compliance[Severity] = "Medium", 2,
                Compliance[Severity] = "Low", 1
            )
    )
VAR _grouptable =
    GROUPBY (
        _t,
        Compliance[Date],
        Compliance[Non Compliance],
        "@count", SUMX ( CURRENTGROUP (), 1 ),
        "@tiebreak", SUMX ( CURRENTGROUP (), [@tiebreaker] )
    )
VAR _highest =
    MAXX (
        ADDCOLUMNS ( _grouptable, "@value", [@count] * 10 + [@tiebreak] ),
        [@value]
    )
RETURN
    IF (
        HASONEVALUE ( Compliance[Date] ),
        CONCATENATEX (
            FILTER (
                ADDCOLUMNS ( _grouptable, "@value", [@count] * 10 + [@tiebreak] ),
                [@value] = _highest
            ),
            Compliance[Non Compliance],
            ", "
        )
    )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.