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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
TM
Advocate I
Advocate I

Comparing Sales Orders (rows) and keeping the highest version number - two column filtering

Hi,

 

I have got two columns, "Sales Orders" and "Version number". The sales have a correlating ID in this format: "M00123456". The data comes from an Access database. The version number is a whole number from 1 to infinity.

 

Every order have a version number. When the order changes (for instance, when the shipping address is updated) a new record is added and the old record is kept as-is (the user adds a new record in the Access Web App). This means that I need to do a filter that searches for a specific order with a version number higher than 1, with that I wan't to remove every version but the newest/highest version number. But it can't be a static search for a sales order, I must do it for every sales order.

 

Example: 

Sales Order               Version number

M00123456               1           <--- Do nothing

M00234567               1           <--- Discard

M00234567               2           <--- Display this one

M00345678               1           <--- Discard 

M00345678               2           <--- Discard 

M00345678               3           <--- Display this one

....                              ...

 

For instance, Sales Order "M00234567" - I only wan't to display the latest version, the one with version number 2. Essentially I wan't to display this:

 

Sales Order               Version number

M00123456               1           <--- Do nothing

M00234567               2           <--- Display this one

M00345678               3           <--- Display this one

 

Essentially, I need to discard every sales order but the one with the highest version number for every specific Sales Order ID.

 

Is this even possible to do? It feels like I've tried everything I can think of... Anyone with an idea how to solve this?

Thanks in advance for any help!

 

Sincerely,

TM

1 ACCEPTED SOLUTION
LarsSchreiber
Responsive Resident
Responsive Resident

Hi @TM,

 

I can only agree with @itchyeyeballs: Grouping in combination with a MAX function should solve your problem. I copied your table into Excel and then pulled it into Power Query. My script looks like this 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
    #"Change Type" = Table.TransformColumnTypes(Source,{{"Sales Order            ", type text}, {"  Version number", Int64.Type}}),
    #"Group Rows" = Table.Group(#"Change Type", {"Sales Order            "}, {{"HighestVersionNumber", each List.Max([#"  Version number"]), type number}})
in
    #"Group Rows"

The result is the following:

 

01.jpg

 

 

 

 

 

Hope that helps.

 

Regards,

Lars

View solution in original post

6 REPLIES 6
LarsSchreiber
Responsive Resident
Responsive Resident

Hi @TM,

 

I can only agree with @itchyeyeballs: Grouping in combination with a MAX function should solve your problem. I copied your table into Excel and then pulled it into Power Query. My script looks like this 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
    #"Change Type" = Table.TransformColumnTypes(Source,{{"Sales Order            ", type text}, {"  Version number", Int64.Type}}),
    #"Group Rows" = Table.Group(#"Change Type", {"Sales Order            "}, {{"HighestVersionNumber", each List.Max([#"  Version number"]), type number}})
in
    #"Group Rows"

The result is the following:

 

01.jpg

 

 

 

 

 

Hope that helps.

 

Regards,

Lars

itchyeyeballs
Impactful Individual
Impactful Individual

 

edit @konstantinos beat me to it with a better solution

 

 @itchyeyeballs Haha!! Actually @LarsSchreiber was simpler than mine and didn't had time to imrove mine to show correct totals.

But tell us your thinking because it always useful, and if not in this usually in other problems

Konstantinos Ioannou

I typed out a soultion for using the group by functionality (either in Access or power query) to create a lookup table, using the max function to only return the highest version number.

 

May be a way to go if @TM doesn't wan't the other order data in his model at all I suppose.

@itchyeyeballs you are right since if not using old data anywhere else, this can help navigating to data model and also performance, specially if the fact table contains millions of rows.

Konstantinos Ioannou
konstantinos
Memorable Member
Memorable Member

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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