Forum Discussion

RichOB's avatar
RichOB
Post Partisan
1 year ago
Solved

Top1 measure

Hi, I'm looking to get the Top1 based on the IT_Issue with the highest difference. Here is my sample data:

 

LocationBasedIT_Issue2023-20242024-2024Difference
LondonLocal OfficeLaptop43733
LondonLocal OfficeEmail6104
LondonLocal OfficePrinter891
ManchesterLocal OfficeLaptop123624
ManchesterLocal OfficeEmail71710
ManchesterLocal OfficePrinter4106
LondonFieldLaptop264
LondonFieldEmail121
LondonFieldPrinter242
ManchesterFieldLaptop85-3
ManchesterFieldEmail12164
ManchesterFieldPrinter10199
LondonCentral ServicesLaptop182911
LondonCentral ServicesEmail11110
LondonCentral ServicesPrinter682
ManchesterCentral ServicesLaptop137-6
ManchesterCentral ServicesEmail71912
ManchesterCentral ServicesPrinter242

 

This is what I need:

IT_IssueLocationBasedTypeDifference
LaptopLondonLocal-OfficeLaptop33
EmailManchesterCentral ServicesEmail12
PrinterManchesterFieldPrinter9

 

Thanks

  • Hi RichOB 

    Can you please try the below DAX?

    Create a new table and use the below DAX, which returns a table 

    TopITIssuesByDifference =
    VAR RankedTable =
        ADDCOLUMNS(
            'Table',  -- Replace with your actual table name
            "Rank",
            RANKX(
                FILTER('Table', 'Table'[IT_Issue] = EARLIER('Table'[IT_Issue])),
                'Table'[Difference],
                ,
                DESC,
                DENSE
            )
        )
    RETURN
        SELECTCOLUMNS(
            FILTER(RankedTable, [Rank] = 1),
            "IT_Issue", [IT_Issue],
            "Location", [Location],
            "Based", [Based],
            "Type", [IT_Issue],
            "Difference", [Difference]
        )

     

     

    If this answers your questions, kindly accept it as a solution and give kudos.

3 Replies

  • Deku's avatar
    Deku
    Super User

    VAR maxDiff=

    Calaculate(

    Max( table[difference]),

    ALLEXCEPT( table, table[location])

    )

    Return 

    Countrows(

    Filter(

    Table,

    Table[difference] = maxDiff

    )

    )

     

    Add this to the filter pane for the table visual, and set to where count >0

  • Hi RichOB 

    Can you please try the below DAX?

    Create a new table and use the below DAX, which returns a table 

    TopITIssuesByDifference =
    VAR RankedTable =
        ADDCOLUMNS(
            'Table',  -- Replace with your actual table name
            "Rank",
            RANKX(
                FILTER('Table', 'Table'[IT_Issue] = EARLIER('Table'[IT_Issue])),
                'Table'[Difference],
                ,
                DESC,
                DENSE
            )
        )
    RETURN
        SELECTCOLUMNS(
            FILTER(RankedTable, [Rank] = 1),
            "IT_Issue", [IT_Issue],
            "Location", [Location],
            "Based", [Based],
            "Type", [IT_Issue],
            "Difference", [Difference]
        )

     

     

    If this answers your questions, kindly accept it as a solution and give kudos.
  • Hi RichOB,

    By using the DAX below, you can achieve your desired result of getting the Top 1 IT_Issue with the highest Difference across each category:

    Top1_Issues = 
    FILTER (
    ADDCOLUMNS (
    'IT_Issues',
    "MaxDiff", CALCULATE (
    MAX('IT_Issues'[Difference]),
    ALLEXCEPT('IT_Issues', 'IT_Issues'[IT_Issue])
    )
    ),
    [Difference] = [MaxDiff]
    )

    You can use the resulting Top1_Issues table in a visual by adding the fields:

    IT_Issue, Location, Based, Type (add as a new column: Type = [IT_Issue]) &Difference

    Let me know if you want it as a measure instead of a table!

    Hope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
    💡Found it helpful? Show some love with kudos 👍 as your support keeps our community thriving!
    🚀Let’s keep building smarter, data-driven solutions together! 🚀[Explore More]