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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply

Index by pattern

Hello,

My data have a pattern, generally of 4 rows, but sometimes it breaks by 3 or 5 rows.

I am looking for solution to start again the "pattern_index" from zero every time I have TRUE in the "pattern" column.

As now I use Number.Mod([index], 4) in the "patten_index".

Thanks in advance

 

indexpatternpattern_index
0TRUE0
1FALSE1
2FALSE2
3FALSE3
4TRUE0
5FALSE1
6FALSE2
7FALSE3
8TRUE0
9FALSE1
10FALSE2
11FALSE3
12TRUE0
13FALSE1
14FALSE2
15FALSE3
16TRUE0
17FALSE1
18FALSE2
19FALSE3
20TRUE0
21FALSE1
22FALSE2
23TRUE3
24FALSE0
25FALSE1
26FALSE2
27TRUE3
28FALSE0
29FALSE1
1 ACCEPTED SOLUTION
dufoq3
Community Champion
Community Champion

Hi @Ara_Karapetyan,,

 

Fastest solution:

dufoq3_0-1710061423617.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XZArDoAwEAXvshrRfS20SAQoFB/V9P7XgATTQU52J5m8Wi3YYNdxr9aGav7CtuznRwJFUOq1EacJlEGl12acPBDZ4kInYzwR2eMTVAZ5IbJJWEe/ebiPIn6ZJCaJGylDZZK6pPYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [index = _t, pattern = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"pattern", type logical}, {"index", Int64.Type}}),
    IndexPattern = 
        [ p = List.Buffer(ChangedType[pattern]),
          lg = List.Generate( 
            ()=> [ x = 0, y = 0 ],
            each [x] <= List.Count(p) -1,
            each [ x = [x]+1, y = if p{x} = true then 0 else [y]+1 ],
            each [y] )
        ][lg],
    Ad_IndexPattern = Table.FromColumns(Table.ToColumns(ChangedType) & {IndexPattern}, Table.ColumnNames(ChangedType) & {"Index Pattern"})
in
    Ad_IndexPattern

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Community Champion
Community Champion

Hi @Ara_Karapetyan,,

 

Fastest solution:

dufoq3_0-1710061423617.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XZArDoAwEAXvshrRfS20SAQoFB/V9P7XgATTQU52J5m8Wi3YYNdxr9aGav7CtuznRwJFUOq1EacJlEGl12acPBDZ4kInYzwR2eMTVAZ5IbJJWEe/ebiPIn6ZJCaJGylDZZK6pPYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [index = _t, pattern = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"pattern", type logical}, {"index", Int64.Type}}),
    IndexPattern = 
        [ p = List.Buffer(ChangedType[pattern]),
          lg = List.Generate( 
            ()=> [ x = 0, y = 0 ],
            each [x] <= List.Count(p) -1,
            each [ x = [x]+1, y = if p{x} = true then 0 else [y]+1 ],
            each [y] )
        ][lg],
    Ad_IndexPattern = Table.FromColumns(Table.ToColumns(ChangedType) & {IndexPattern}, Table.ColumnNames(ChangedType) & {"Index Pattern"})
in
    Ad_IndexPattern

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Brilliant!

Thank you!

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.