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
CA8172
Helper I
Helper I

Needing help with a MAX and/or RANK order to provide a specific status

Good Day All,

 

I have one table that has customer order information and the status of the order, as well as, another table with a ranking order.  I'm trying to condense the order number to provide the current status order based on a rank.

 

Below is my customer information table (Order No, Trans ID, Status):

ORDER NOTRANS IDSTATUS
147852001In Progress
147852002Packaged
147852003Sent
201456001In Progress
201456002Packaged
369852001Sent
369852002Sent
369852003Sent
410236001Packaged
410236002Sent

 

Here is the ranking table (Status, Rank):

STATUSRANK
In Progress1
Packaged2
Sent3

 

I'm trying to come up with a column that gives me one order number to the highest rank so that my table would show the below, so we know where the actual order truly stands (Order No, Status -Formula-).

ORDER NOSTATUS (Formula)
147852In Progress
201456In Progress
369852Sent
410236Packaged

 

Any assistance would greatly be appreciated.  Thanks!

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

There are probably better ways to do this, but this one works.  It assumes you have a relationship between your Orders and Rank table (that's what I called them, so replace as necessary) on the Status column.  I noted your Orders table already has a ranks column (001, 002, etc.), but I assume that is just how you made the sample data so did not use that column.

 

If you can use the Trans ID column, you can just use this measure

Latest Status 2 = var mintransid = MIN(Orders[TRANS ID])
return CALCULATE(MIN(Orders[STATUS]), Orders[TRANS ID] = mintransid)

 

If not, here is one that uses both of your tables

 

Latest Status =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE ( Orders, Orders[ORDER NO], Orders[STATUS] ),
        "@StatusRank", CALCULATE ( MIN ( 'Rank'[RANK] ) )
    )
VAR toprank =
    TOPN ( 1, summarytable, [@StatusRank], ASC )
RETURN
    MINX ( toprank, Orders[STATUS] )

 

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

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

3 REPLIES 3
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
Employee
Employee

There are probably better ways to do this, but this one works.  It assumes you have a relationship between your Orders and Rank table (that's what I called them, so replace as necessary) on the Status column.  I noted your Orders table already has a ranks column (001, 002, etc.), but I assume that is just how you made the sample data so did not use that column.

 

If you can use the Trans ID column, you can just use this measure

Latest Status 2 = var mintransid = MIN(Orders[TRANS ID])
return CALCULATE(MIN(Orders[STATUS]), Orders[TRANS ID] = mintransid)

 

If not, here is one that uses both of your tables

 

Latest Status =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE ( Orders, Orders[ORDER NO], Orders[STATUS] ),
        "@StatusRank", CALCULATE ( MIN ( 'Rank'[RANK] ) )
    )
VAR toprank =
    TOPN ( 1, summarytable, [@StatusRank], ASC )
RETURN
    MINX ( toprank, Orders[STATUS] )

 

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

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


Thank you...preliminary finding has this working for me.

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.