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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Super User
Super User

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
Super User
Super User

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors