Ranking Data based on 2 Sort groups

spudd

New Member
Joined
Jan 18, 2011
Messages
18
Good Morning
Any ideas on how to do this in a measure.... Create a Ranking based upon a date from Earliest to Latest, where SALES DATE is Grouped and Machine is grouped.

My Data looks something like this, but continues for upto 42 days and involves some 30 other fields in the table but these are the fields I need. It is a direct query so cannot add to the table set in power BI
So Data looks like this
SalesdateMachine LocationTime Start
24/02/2023W7P123/02/2023 08:00
24/02/2023W7P223/02/2023 06:00
24/02/2023W7P123/02/2023 12:45
24/02/2023W7P123/02/2023 19:00
24/02/2023W7P123/02/2023 21:45
24/02/2023W7P223/02/2023 10:45
24/02/2023W7P123/02/2023 22:00
24/02/2023W13P123/02/2023 09:52
24/02/2023W13P123/02/2023 11:47
24/02/2023W13P123/02/2023 12:56
24/02/2023W13P223/02/2023 08:00
24/02/2023W13P123/02/2023 14:57
24/02/2023W13P223/02/2023 16:23
24/02/2023W13P223/02/2023 08:00
24/02/2023W13P123/02/2023 18:00
24/02/2023W13P223/02/2023 19:32


I am looking to produce a result something like this with a Ranking... where salesates and machine are the same
SalesdateMachine LocationTime StartRanking
24/02/2023W13P123/02/2023 09:521
24/02/2023W13P123/02/2023 11:472
24/02/2023W13P123/02/2023 12:563
24/02/2023W13P123/02/2023 14:574
24/02/2023W13P123/02/2023 18:005
24/02/2023W13P223/02/2023 08:001
24/02/2023W13P223/02/2023 08:002
24/02/2023W13P223/02/2023 16:233
24/02/2023W13P223/02/2023 19:324
24/02/2023W7P123/02/2023 08:001
24/02/2023W7P123/02/2023 12:452
24/02/2023W7P123/02/2023 19:003
24/02/2023W7P123/02/2023 21:454
24/02/2023W7P123/02/2023 22:005
24/02/2023W7P223/02/2023 06:001
24/02/2023W7P223/02/2023 10:452

 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Starting with your second table so I knew if I got it right!:
Book1
ABC
1SalesdateMachine LocationTime Start
224/02/2023W13P123/02/2023 09:52
324/02/2023W13P123/02/2023 11:47
424/02/2023W13P123/02/2023 12:56
524/02/2023W13P123/02/2023 14:57
624/02/2023W13P123/02/2023 18:00
724/02/2023W13P223/02/2023 08:00
824/02/2023W13P223/02/2023 08:00
924/02/2023W13P223/02/2023 16:23
1024/02/2023W13P223/02/2023 19:32
1124/02/2023W7P123/02/2023 08:00
1224/02/2023W7P123/02/2023 12:45
1324/02/2023W7P123/02/2023 19:00
1424/02/2023W7P123/02/2023 21:45
1524/02/2023W7P123/02/2023 22:00
1624/02/2023W7P223/02/2023 06:00
1724/02/2023W7P223/02/2023 10:45
Sheet2

Brought it into Power Query:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    ChangedTypeWithLocale = Table.TransformColumnTypes(Source, {{"Salesdate", type date}}, "en-GB"),
    ChangedType = Table.TransformColumnTypes(ChangedTypeWithLocale,{{"Machine Location", type text}}),
    ChangedTypeWithLocale1 = Table.TransformColumnTypes(ChangedType, {{"Time Start", type datetime}}, "en-GB"),
    GroupedRows = Table.Group(ChangedTypeWithLocale1, {"Salesdate", "Machine Location"}, {{"TS", each _, type table [Salesdate=nullable date, Machine Location=nullable text, Time Start=nullable datetime]}}),
    AddedCustom = Table.AddColumn(GroupedRows, "Custom", each Table.AddIndexColumn( [TS], "Rank", 1 )),
    RemovedTS = Table.RemoveColumns(AddedCustom,{"TS"}),
    ExpandedCustom = Table.ExpandTableColumn(RemovedTS, "Custom", {"Time Start", "Rank"}, {"Time Start", "Rank"}),
    ChangedType1 = Table.TransformColumnTypes(ExpandedCustom,{{"Time Start", type datetime}, {"Rank", Int64.Type}})
in
    ChangedType1
Resulting in this table with a check against your values:
Book1
EFGHIJKL
1SalesdateMachine LocationTime StartRankMatch?Source Ranking
202/24/2023W13P102/23/2023 09:521TRUE1
302/24/2023W13P102/23/2023 11:472TRUE2
402/24/2023W13P102/23/2023 12:563TRUE3
502/24/2023W13P102/23/2023 14:574TRUE4
602/24/2023W13P102/23/2023 18:005TRUE5
702/24/2023W13P202/23/2023 08:001TRUE1
802/24/2023W13P202/23/2023 08:002TRUE2
902/24/2023W13P202/23/2023 16:233TRUE3
1002/24/2023W13P202/23/2023 19:324TRUE4
1102/24/2023W7P102/23/2023 08:001TRUE1
1202/24/2023W7P102/23/2023 12:452TRUE2
1302/24/2023W7P102/23/2023 19:003TRUE3
1402/24/2023W7P102/23/2023 21:454TRUE4
1502/24/2023W7P102/23/2023 22:005TRUE5
1602/24/2023W7P202/23/2023 06:001TRUE1
1702/24/2023W7P202/23/2023 10:452TRUE2
Sheet2
Cell Formulas
RangeFormula
J2:J17J2=Rankings2[@Rank]=L2

I had to use Locale to get the proper data type in PQ, you should be able to remove those lines and use the existing Change Type steps to set the data types for the Salesdate and Time Start columns. The important steps are the grouping of the rows and adding an Index column to each group's table.
BTW, you should add what version of Excel you're using to your Profile, and use XL2BB when posting data. Makes life a lot easier for those that want to help.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top