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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
maclura
Resolver I
Resolver I

Data transformation with calculation with M

Hi,

I have a connection to a SQL Server Instance importing a over million rows table on which I want to perform a simple manipulation on some data before import, but I don't know if this is possible (or makes sense) with M.

 

Basically this is the table

ItemCost
abc10
abc7
abc0
mnl0
xyz0
xyz0
xyz0

 

and what I want to do is:

- if "Item" is not duplicated, or all the "Cost" values in the duplication are equal to 0, do nothing (import as they are now).

- if "Item" is DUPLICATED

      - find the MAX "Cost" value in the duplication,

      - and set all the "Cost" zero value occurrencies to the MAX "Cost" value. 

 

The above table, after importation should look like

ItemCost
abc10
abc7
abc10
mnl0
xyz0
xyz0
xyz0

 

Thank you for any advice.

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@maclura 

You need to group and a little custom column to get it. Please check the attached file below my signature.

Fowmy_0-1619441175522.png

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

@maclura 

 

Because you selected both item and cost columns before grouping, I selected only item.

 

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@maclura 

You need to group and a little custom column to get it. Please check the attached file below my signature.

Fowmy_0-1619441175522.png

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you @Fowmy 
Your suggested solution does work with me.


I'd never used the Table.ReplaceValue function.

I have just an additional question which is more curiosity than other.

In your code I read this line

= Table.Group(#"Changed Type1", {"Item"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Max", each List.Max([Cost]), type nullable number}, {"All", each _, type table [Item=nullable text, Cost=nullable number]}})

instead, when I recreated the same using the 'Group by' widzard, this is what I read:

= Table.Group(#"Changed Type1", {"Item", "Cost"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Max", each List.Max([Cost]), type nullable number}, {"All", each _, type table [Item=nullable text, Cost=nullable number]}})

why?

@maclura 

 

Because you selected both item and cost columns before grouping, I selected only item.

 

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.