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

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

Reply
Anonymous
Not applicable

TOP1 measure with double filter

I'm stuck with a simple task and I need your help.

 

I have a simple dataset where I need to show top1 state by the number of alerts.

I can write a measure that calculates it correctly in case we have an obvious leader.

 

But when there are several states with the same number of alerts, I need to show the one that was recorder most recently.

Other than that I shouls show the number of alerts over this period of time.

 

Please help

 

https://drive.google.com/file/d/1M4Oe9REDZ0xHq7gFVh2KimNXw4DIqadh/view?usp=sharing 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression.  Note that your original measure was not correct as it did not have CALCULATE() around the COUNT.  This expression makes a virtual table with the states, their counts, and a small # (<1) to differentiate based on most recently reported.  The sum of these is used to get a single Top 1.  Note you could have concatenated your Top1 so that if a tie occurs both would show.

 

Top1 New =
VAR summary =
    ADDCOLUMNS (
        ADDCOLUMNS (
            DISTINCT ( Sheet1[State] ),
            "cCount",
                CALCULATE (
                    COUNT ( Sheet1[Alerts] )
                ),
            "cDays",
                1
                    / (
                        2
                            CALCULATE (
                                DATEDIFF (
                                    MAX ( Sheet1[Date ] ),
                                    TODAY (),
                                    DAY
                                )
                            )
                    )
        ),
        "cTotal",
            [cDays] + [cCount]
    )
VAR maxtotal =
    MAXX (
        summary,
        [cTotal]
    )
RETURN
    MINX (
        FILTER (
            summary,
            [cTotal] = maxtotal
        ),
        Sheet1[State]
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression.  Note that your original measure was not correct as it did not have CALCULATE() around the COUNT.  This expression makes a virtual table with the states, their counts, and a small # (<1) to differentiate based on most recently reported.  The sum of these is used to get a single Top 1.  Note you could have concatenated your Top1 so that if a tie occurs both would show.

 

Top1 New =
VAR summary =
    ADDCOLUMNS (
        ADDCOLUMNS (
            DISTINCT ( Sheet1[State] ),
            "cCount",
                CALCULATE (
                    COUNT ( Sheet1[Alerts] )
                ),
            "cDays",
                1
                    / (
                        2
                            CALCULATE (
                                DATEDIFF (
                                    MAX ( Sheet1[Date ] ),
                                    TODAY (),
                                    DAY
                                )
                            )
                    )
        ),
        "cTotal",
            [cDays] + [cCount]
    )
VAR maxtotal =
    MAXX (
        summary,
        [cTotal]
    )
RETURN
    MINX (
        FILTER (
            summary,
            [cTotal] = maxtotal
        ),
        Sheet1[State]
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

It works, thank you! I would need several days to understand what it does inside but it makes the job.

amitchandak
Super User
Super User

@Anonymous , I am assuming you need a rank tie breaker to overcome this

refer https://community.powerbi.com/t5/Community-Blog/Breaking-Ties-in-Rankings-with-RANKX-Using-Multiple-Columns/ba-p/918655
https://databear.com/how-to-use-the-dax-rankx-function-in-power-bi/

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
Anonymous
Not applicable

Hi @amitchandak ,

 

But what I see following this link is a simple ranking by kind of index column.

Sorry, looks like it doesn't apply to my example.

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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