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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
samahiji
Frequent Visitor

Pick the first occurrence then step by number (n)

Hi,

I have a table of X and Y values, where either X or Y increases by a step of n. I need Power Query to first identify which column (X or Y) has the increasing trend by n. Then, apply a formula to the identified column by selecting the first occurrence after each step of n.

 

X_Y_Step_5.JPG

1 ACCEPTED SOLUTION
Omid_Motamedise
Super User
Super User

Hi @samahiji 

 

Just copy and past the below formula in advance editor

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRy1jU0MlbSUTIEYiOlWB1kMRA2QxOzAGJzNDFDI7AEmqAZFpVGIGtM0QRNQKoN4YImpmZQu4GyqILmIEFTbIKWaIIgZxoboAkaGoBsA/ooFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ABC = _t, X = _t, Y = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ABC", type text}, {"X", Int64.Type}, {"Y", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ABC", "X", "Y"}, {},0,(a,b)=> Number.From(b[X]-a[X]>=5 or b[Y]-a[Y]>=5))
in
#"Grouped Rows"

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

1 REPLY 1
Omid_Motamedise
Super User
Super User

Hi @samahiji 

 

Just copy and past the below formula in advance editor

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRy1jU0MlbSUTIEYiOlWB1kMRA2QxOzAGJzNDFDI7AEmqAZFpVGIGtM0QRNQKoN4YImpmZQu4GyqILmIEFTbIKWaIIgZxoboAkaGoBsA/ooFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ABC = _t, X = _t, Y = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ABC", type text}, {"X", Int64.Type}, {"Y", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ABC", "X", "Y"}, {},0,(a,b)=> Number.From(b[X]-a[X]>=5 or b[Y]-a[Y]>=5))
in
#"Grouped Rows"

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 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.