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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
nazdravanul
Frequent Visitor

Create conditional index column based on row values - at Querry level

Existing column    Required ouptut on custom column

 

BAB                     0  

BAB                     1

BAB                     2

CIC                      0
CIC                      1
CIC                      2
CIC                      3
CIC                      4

DDE                     0
DDE                     1

 

This is a very important issue for our business and despite the simple form I couldn't solve it in Power BI, until now. It needs to be done in M Querry, in order to allow a subsequent join with another table / data source, so a DAX solution will not help. 

1 ACCEPTED SOLUTION
Interkoubess
Solution Sage
Solution Sage

Hi @nazdravanul,

 

I copied and pasted your data in my model ( I called Data), and this is the Power Query code ( with Advanced Editor) :

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnJ0UorVwaSdPZ2Jol1cXBF0LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Test = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Test"}, {{"Count", each Table.AddIndexColumn(_,"Index",0,1), type table}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Index"}, {"Index"})
in
    #"Expanded Count"

So you can replace the source and then copy and paste the rest....

 

Ninter...Index.PNG

View solution in original post

2 REPLIES 2
Interkoubess
Solution Sage
Solution Sage

Hi @nazdravanul,

 

I copied and pasted your data in my model ( I called Data), and this is the Power Query code ( with Advanced Editor) :

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnJ0UorVwaSdPZ2Jol1cXBF0LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Test = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Test"}, {{"Count", each Table.AddIndexColumn(_,"Index",0,1), type table}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Index"}, {"Index"})
in
    #"Expanded Count"

So you can replace the source and then copy and paste the rest....

 

Ninter...Index.PNG

Thank you very much - with a bit of tinkering, in order to adjust it to my existing querry, this worked like a charm! 🙂 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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