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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.