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
Enric21
Frequent Visitor

Get the total amount of a column regarding the latest version of a project

Hi all, 

 

I hope someone can help me. 

 

I have a table with some projects and each project have several versions, furtheremore those versions have lots of sales within the version. My table is something like this:

 

Project IDVersiónSales
1010
1020
11100
1230
1240
2015
2070
2115
2120
2115
3020
3150
3230

 

I would like to get a table filtering only the latest version of each project (and making the sum of the sales column), so the result wuold be like this:

 

Project IDVersiónSales
1270
2150
3230

 

Thank you all in advance. 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You don't even need DAX for this.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIAYkMDpVgdBNcIwQVjAwTfCIiNUbkmEK4RzCxTFK45QtYQVdYQYROarDGqO4yhsqYILswZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Versión = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Versión", Int64.Type}, {"Sales", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Project ID", "Versión"}, {{"Sales", each List.Sum([Sales]), type nullable number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Project ID", Order.Ascending}, {"Versión", Order.Descending}}),
    #"Grouped Rows1" = Table.Group(#"Sorted Rows", {"Project ID"}, {{"Version", each List.Max([Versión]), type nullable number}, {"Sales", each _, type table [Project ID=nullable number, Versión=nullable number, Sales=nullable number]}}),
    #"Replaced Value" = Table.ReplaceValue(#"Grouped Rows1",each [Sales],each [Sales]{0},Replacer.ReplaceValue,{"Sales"}),
    #"Expanded Sales" = Table.ExpandRecordColumn(#"Replaced Value", "Sales", {"Sales"}, {"Sales.1"})
in
    #"Expanded Sales"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @Enric21 

Could you please tell me whether your problem has been solved?

If yes, please accept the helpful answer as solution to close this thread. 

 

Best Regards,
Community Support Team _ Eason

lbendlin
Super User
Super User

You don't even need DAX for this.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIAYkMDpVgdBNcIwQVjAwTfCIiNUbkmEK4RzCxTFK45QtYQVdYQYROarDGqO4yhsqYILswZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project ID" = _t, Versión = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project ID", Int64.Type}, {"Versión", Int64.Type}, {"Sales", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Project ID", "Versión"}, {{"Sales", each List.Sum([Sales]), type nullable number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Project ID", Order.Ascending}, {"Versión", Order.Descending}}),
    #"Grouped Rows1" = Table.Group(#"Sorted Rows", {"Project ID"}, {{"Version", each List.Max([Versión]), type nullable number}, {"Sales", each _, type table [Project ID=nullable number, Versión=nullable number, Sales=nullable number]}}),
    #"Replaced Value" = Table.ReplaceValue(#"Grouped Rows1",each [Sales],each [Sales]{0},Replacer.ReplaceValue,{"Sales"}),
    #"Expanded Sales" = Table.ExpandRecordColumn(#"Replaced Value", "Sales", {"Sales"}, {"Sales.1"})
in
    #"Expanded Sales"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

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.