Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Good morning, I need help!
How can I in Power Query create a conditional index column, I explain:
I need to generate a conditional index column, so that it only lists the columns that have non-zero values, so in the image data it should have from 1 to 5 and the values that are 0 do not have a number. Can anyone help me?
Solved! Go to Solution.
Hi @Syndicate_Admin @nataliaguzman02
Download example PBIX file with the following code
This query does what you want
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjA3MDBQitWJVkImzYxMDdBZENLI2ACbBqikoRkOyVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cportafolio_t.Rendimento Mercado" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cportafolio_t.Rendimento Mercado", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Cportafolio_t.Rendimento Mercado] <> 0 then List.Count(List.RemoveMatchingItems(List.RemoveLastN(#"Added Index"[Cportafolio_t.Rendimento Mercado],List.Count(#"Added Index"[Cportafolio_t.Rendimento Mercado])-[Index]),{0}) ) else ""),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
#"Removed Columns"
Regards
Phil
Proud to be a Super User!
Hi @Syndicate_Admin @nataliaguzman02
Download example PBIX file with the following code
This query does what you want
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjA3MDBQitWJVkImzYxMDdBZENLI2ACbBqikoRkOyVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cportafolio_t.Rendimento Mercado" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cportafolio_t.Rendimento Mercado", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Cportafolio_t.Rendimento Mercado] <> 0 then List.Count(List.RemoveMatchingItems(List.RemoveLastN(#"Added Index"[Cportafolio_t.Rendimento Mercado],List.Count(#"Added Index"[Cportafolio_t.Rendimento Mercado])-[Index]),{0}) ) else ""),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
#"Removed Columns"
Regards
Phil
Proud to be a Super User!
Thank you very much for your help!
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 58 | |
| 52 | |
| 40 | |
| 17 | |
| 16 |
| User | Count |
|---|---|
| 112 | |
| 109 | |
| 40 | |
| 33 | |
| 27 |