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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Write value on every 5 rows

Dear Power Bi community,

Do you know how I can write in PowerQuery:

 

To index the rows based on their date ( earliest to latest) and to index them only if they have a special text value ( for example "text")

 

After the indexing is done, to write in another new column the value "text2" every 5 rows?

 

1 ACCEPTED SOLUTION
HotChilli
Community Champion
Community Champion

Yes, it's achievable.  Sort the data on 2 columns (text, date).

Then do a 'Group By' on Text, using the All Rows aggregation.

Then add an index within each group with code similar to this:

Add a custom column

Table.AddIndexColumn([all], "sub", 1, 1, Int64.Type)

[all] is the name of the All Rows column from the previous step.

Remove the columns that you don't want and expand the column headers to return the required data.

Good luck

View solution in original post

7 REPLIES 7
HotChilli
Community Champion
Community Champion

Yes, it's achievable.  Sort the data on 2 columns (text, date).

Then do a 'Group By' on Text, using the All Rows aggregation.

Then add an index within each group with code similar to this:

Add a custom column

Table.AddIndexColumn([all], "sub", 1, 1, Int64.Type)

[all] is the name of the All Rows column from the previous step.

Remove the columns that you don't want and expand the column headers to return the required data.

Good luck

HotChilli
Community Champion
Community Champion

Make 2 copies of the table (using Duplicate from the interface)

1st table : Filter out rows with text in Column2 (from the column header). 

2nd table : Filter out rows with no text in Column2.  Sort the Date column ascending. Add an Index (from Add Column menu).

Add a column (with your column name inserted)  :

if Number.Mod([IndexCol], 5) = 0 then "SKIP LOT" else ""

 

---

Append the 2 tables (from the interface)

--

That should do it.  Let me know how it goes

Anonymous
Not applicable

Hello, Thanks a lot it worked. Do you know if there is this complication: we have different texts, and I want to index based on the value "texts".

 

For the first Step I will sort the rows based on ascending date. But how can I index based on the text value? Example is below

 

For instance:

Text ValueDateIndex
Text A02/12/20212
Text A01/12/20211
Text B01/12/20211
Text C01/12/20211
Text B02/12/20212
Text C02/12/20212
Text A03/12/20213
Text A04/12/20214
KNP
Super User
Super User

Yes, with sort function, custom conditional index column and math.

Please provide some data. 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!
Anonymous
Not applicable

So everything is in the same table.  I want the results to look like this.

The index based on the column 2 if I have "text" and in a chronological order by date. And every 5 indexes, to write in the new Column : Skip Lot

 

Column 1Column 2DateIndexnew Colum
a    
btext05/12/20212 
ctext06/12/20213 
d    
etext07.12/20214 
f    
gtext08/12/20215SKIP LOT
htext01/12/20211 
smpa01
Community Champion
Community Champion

@Anonymous  providing sample data and desired output would be a good start

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

vstoytch_0-1638534873316.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.