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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Get next 3 row values for current row

I already got the solution for the next table with Power Query (grouping, indexing, combining, expanding, etc.), but when I load all the data, Power BI can't process it, it takes hours without getting the final report.
I have the "Sequence" (it is already grouped) and "Value" columns and at the end I added three indexes and combined the table also three times against itself (more than half millon rows aprox), to get the next three values; I think these three final combining and expanding processes are the reason for this delay. Somebody can supply a DAX code to avoid long process time.
By the way, the previous combining and expanding commands are also slow, but at least take no more than 5 minutes to process.

 

Source Resuts  
SequenceValueNext1Next2Next3
1SKUMTTOCIPCAM
2MTTOCIPCAMSKU
4CIPCAMSKUCAM
5CAMSKUCAMMTTO
6SKUCAMMTTO 
10CAMMTTO  
11MTTO   
1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want a measure in table visual, parry2k’s solution is proper and great.

But if you want actual column in table, We can create following calculate columns to meet your requirement.

 

Next 1 = 
var x = CALCULATE(MIN('Table'[Sequence]),FILTER('Table','Table'[Sequence]>EARLIER('Table'[Sequence])))
return
CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Sequence]=x))

 

Next 2 = 
var x = CALCULATE(MIN('Table'[Sequence]),FILTER('Table','Table'[Sequence]>EARLIER('Table'[Sequence])))
return
CALCULATE(MAX('Table'[Next 1]),FILTER('Table','Table'[Sequence]=x))

 

Next 3 = 
var x = CALCULATE(MIN('Table'[Sequence]),FILTER('Table','Table'[Sequence]>EARLIER('Table'[Sequence])))
return
CALCULATE(MAX('Table'[Next 2]),FILTER('Table','Table'[Sequence]=x))

 

And the result like this,

 

Annotation 2020-04-16 162625.png

 

BTW, pbix as attached.

 

Best regards,


Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want a measure in table visual, parry2k’s solution is proper and great.

But if you want actual column in table, We can create following calculate columns to meet your requirement.

 

Next 1 = 
var x = CALCULATE(MIN('Table'[Sequence]),FILTER('Table','Table'[Sequence]>EARLIER('Table'[Sequence])))
return
CALCULATE(MAX('Table'[Value]),FILTER('Table','Table'[Sequence]=x))

 

Next 2 = 
var x = CALCULATE(MIN('Table'[Sequence]),FILTER('Table','Table'[Sequence]>EARLIER('Table'[Sequence])))
return
CALCULATE(MAX('Table'[Next 1]),FILTER('Table','Table'[Sequence]=x))

 

Next 3 = 
var x = CALCULATE(MIN('Table'[Sequence]),FILTER('Table','Table'[Sequence]>EARLIER('Table'[Sequence])))
return
CALCULATE(MAX('Table'[Next 2]),FILTER('Table','Table'[Sequence]=x))

 

And the result like this,

 

Annotation 2020-04-16 162625.png

 

BTW, pbix as attached.

 

Best regards,


Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you @v-zhenbw-msft ! It's the solution, I was looking for.

Greg_Deckler
Super User
Super User

OK, I'm missing how you get from Source to Results, can you explain that? I am assuming Source is your source data and includes Sequence and Value columns and that Results is what you want to end up with or am I mistaken?


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg,

That's right. Columns "Sequence" and "Value" are the source data, and results are what I need.

Anonymous
Not applicable

Comment: The numbers in the "Sequence" column are illustrative, because they are the result of previous grouping commands. I use that column only to preserve date/time stamp, removed from this last table. I removed all unnecessary columns to avoid excessive processing time.

@Anonymous here you go, you can surely merge these measure to not create sequence measures

 

Next 1 Sequence = 
VAR __currentRow = SELECTEDVALUE ( Next[Sequence] )
RETURN CALCULATE ( MIN ( Next[Sequence] ), ALL ( Next) , Next[Sequence] > __currentRow )

Next 2 Sequence = 
VAR __currentRow = [Next 1 Sequence]
RETURN CALCULATE ( MIN ( Next[Sequence] ), ALL ( Next) , Next[Sequence] > __currentRow )

Next 3 Sequence = 
VAR __currentRow = [Next 2 Sequence]
RETURN CALCULATE ( MIN ( Next[Sequence] ), ALL ( Next ) , Next[Sequence] > __currentRow )

Next 1 = 
VAR __sequence = [Next 1 Sequence]  
RETURN CALCULATE ( SELECTEDVALUE ( Next[Value] ), ALL(),  Next[Sequence] = __sequence )

Next 2 Sequence = 
VAR __currentRow = [Next 1 Sequence]
RETURN 
CALCULATE ( MIN ( Next[Sequence] ), ALL ( Next) , Next[Sequence] > __currentRow ) 
* DIVIDE ( __currentRow, __currentRow )

Next 3 Sequence = 
VAR __currentRow = [Next 2 Sequence]
RETURN CALCULATE ( MIN ( Next[Sequence] ), ALL ( Next ) , Next[Sequence] > __currentRow )
 *
DIVIDE ( __currentRow, __currentRow )

Value Max = SELECTEDVALUE( Next[Value] )


 

and here is the output

 

image.png

 

image.png



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k !

I'm missing how did you calculate "Next 2" and "Next 3" measures, since you send "Next 2 Sequence" and "Next 3 Sequence" twice. 

@Anonymous not sure if I understood your question, drop all sequence measures in the table visual and you will get the answer.

 

Would appreciate Kudos 🙂 if my solution helped.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thank you very much @parry2k !

Sorry, but I'm not (still) such an expert to use table visual and I didn't require the solution as an added column.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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