This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi, I have a table with 2 fields, one is the description and one is the amount related to description.
But in some case our management system can.'t know if the description is equal to "buy" or to "sell" and so, the system insert in the description the value "-1"
| Description | Amount |
| Sell | 150 |
| Buy | 256 |
| Sell | 895 |
| Sell | 744 |
| Sell | 122 |
| Sell | 252 |
| Buy | 253 |
| Buy | 1236 |
| -1 | 500 |
| -1 | 300 |
Now, to our investor I can't show in my report that there are record equal to -1, and so I would to create a new column and take "Buy" or "Sell" when are "Buy" or "Sell", and I would to insert in place of -1 a value related to this calculation:
1) Sum all the "Buy" and all the "sell". In my example:
| Description | Amount |
| Sell | 2163 |
| Buy | 1745 |
2) and assign the description of the lowest value to -1. So in my example, in the new column there will be in place of -1, Buy.
| New Description | Description | Amount |
| Sell | Sell | 150 |
| Buy | Buy | 256 |
| Sell | Sell | 895 |
| Sell | Sell | 744 |
| Sell | Sell | 122 |
| Sell | Sell | 252 |
| Buy | Buy | 253 |
| Buy | Buy | 1236 |
| Buy | -1 | 500 |
| Buy | -1 | 300 |
thank you.
Carlo
Solved! Go to Solution.
@Carlo1975
You can do it in a power query with simple steps and one custom column. Past the below code on a Blank Query on the Advanced Editr and check the :
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7NyVHSUTI0NVCK1YlWciqtBPKMTM3APKikhaUpMtfcxASZa2hkhMw1MjVCMckYiWdoZAwxWNcQyDM1MEBwjEGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Description = _t, Amount = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Amount", type number}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Description] <> "-1")),
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Description"}, {{"Total", each List.Sum([Amount]), type nullable number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Total", Order.Ascending}}),
#"Kept First Rows" = Table.FirstN(#"Sorted Rows",1),
Custom1 = #"Changed Type",
#"Added Custom" = Table.AddColumn(Custom1, "Custom", each if [Description] = "-1" then #"Kept First Rows"[Description]{0} else [Description])
in
#"Added Custom"
________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@Carlo1975
You can do it in a power query with simple steps and one custom column. Past the below code on a Blank Query on the Advanced Editr and check the :
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7NyVHSUTI0NVCK1YlWciqtBPKMTM3APKikhaUpMtfcxASZa2hkhMw1MjVCMckYiWdoZAwxWNcQyDM1MEBwjEGcWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Description = _t, Amount = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Amount", type number}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Description] <> "-1")),
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Description"}, {{"Total", each List.Sum([Amount]), type nullable number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Total", Order.Ascending}}),
#"Kept First Rows" = Table.FirstN(#"Sorted Rows",1),
Custom1 = #"Changed Type",
#"Added Custom" = Table.AddColumn(Custom1, "Custom", each if [Description] = "-1" then #"Kept First Rows"[Description]{0} else [Description])
in
#"Added Custom"
________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 6 | |
| 6 |