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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors