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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
MonkeySam
Frequent Visitor

Conditional index based on dataset in one column

Hi Experts,
I have referenced this previous solution (https://community.fabric.microsoft.com/t5/Desktop/Conditional-Index/td-p/2840701) but the grouping option looks like not fit my challenge.

My dataset loaded in one column only. I'd like to based on that ABC reference to create the incremental index until the next ABC reference. Each ABC reference is unique.

Can someone please give a thought? Thanks.

 

Example.png

1 ACCEPTED SOLUTION
m_dekorte
Resident Rockstar
Resident Rockstar

Hi @MonkeySam 

try this custom function (create a new blank query, open the advanced editor and replace everything there with this code)

(tbl as table, col as text, optional prefix as text, optional newCol as text) as table =>
let
    p = prefix ?? "ABC",
    n = newCol ?? "Index",
    l = Table.Column(tbl, col),
    i = List.Accumulate(l, {}, (s, x) => s & {if Text.StartsWith(x, p) then 1 else List.Last(s) + 1})
in
    Table.FromColumns(Table.ToColumns(tbl) & {i}, Table.ColumnNames(tbl) & {n})

You can invoke it on your table by filling this out
Selecte the Query, enter the columnName "Data", your prefix and desired name for the conditional index

m_dekorte_0-1776337144924.png


I hope this is helpful

View solution in original post

4 REPLIES 4
MonkeySam
Frequent Visitor

@m_dekorte ,
Your founction works perfectly. Thank you very much!!

Result.png

m_dekorte
Resident Rockstar
Resident Rockstar

Hi @MonkeySam 

try this custom function (create a new blank query, open the advanced editor and replace everything there with this code)

(tbl as table, col as text, optional prefix as text, optional newCol as text) as table =>
let
    p = prefix ?? "ABC",
    n = newCol ?? "Index",
    l = Table.Column(tbl, col),
    i = List.Accumulate(l, {}, (s, x) => s & {if Text.StartsWith(x, p) then 1 else List.Last(s) + 1})
in
    Table.FromColumns(Table.ToColumns(tbl) & {i}, Table.ColumnNames(tbl) & {n})

You can invoke it on your table by filling this out
Selecte the Query, enter the columnName "Data", your prefix and desired name for the conditional index

m_dekorte_0-1776337144924.png


I hope this is helpful

@m_dekorte 
Thanks for the prompt response.
I tried the codes but might miss somewhere. I tried to add a column with "Invoke Custom Function" and referenced to your custom function. "tbl" colum is greyed out and stuck here.

Would you mind to clarify further? Thanks.


Try.png

Right. Yes, this funciton works on the table as a whole so select the function query and fill out the fields, for tbl you can select your Table1 query
Let me know if that worked for you, thanks!

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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