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
kb856
New Member

Rolling 5 row Difference

Hello, 

 

I am new to Power BI and cannot figure out how to create a column that would be simple to create in Excel. I would like to create a new column that takes the difference between every 5 rows for C3A3 ICE Index (shown below). So, it would take the value from May 9, 2017 minus September 8, 2014, then June 16, 2017 - September 11, 2014, and so on. I realize that this would mean there is a blank value in the first 5 rows, since there is not another value to subtract from above them.

 

I would then like to create another column to show "Loss" if the number calculated before is negative (meaning the value decreased over time), and "Gain" if the number is positive (meaning the value increased over time).

 

I will be forever thankful if someone can help. Thanks!

 

kb856_0-1646277983616.png

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Sorry that I cannot know the logic of the order in the Date Column. So, I created a index column that shows the order of each row.

Please check the below picture and the attached pbix file.

 

Picture2.png

 

Expected result CC =
VAR currentrow = Data[Index]
VAR currentvalue = Data[C3A3 ICE Index]
VAR previousvalue =
CALCULATE (
MAX ( Data[C3A3 ICE Index] ),
FILTER ( Data, Data[Index] = currentrow - 4 )
)
RETURN
IF ( previousvalue <> BLANK (), currentvalue - previousvalue )
 
Gain or Loss CC =
IF (
Data[Expected result CC] > 0,
"Gain",
IF ( Data[Expected result CC] < 0, "Loss" )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Sorry that I cannot know the logic of the order in the Date Column. So, I created a index column that shows the order of each row.

Please check the below picture and the attached pbix file.

 

Picture2.png

 

Expected result CC =
VAR currentrow = Data[Index]
VAR currentvalue = Data[C3A3 ICE Index]
VAR previousvalue =
CALCULATE (
MAX ( Data[C3A3 ICE Index] ),
FILTER ( Data, Data[Index] = currentrow - 4 )
)
RETURN
IF ( previousvalue <> BLANK (), currentvalue - previousvalue )
 
Gain or Loss CC =
IF (
Data[Expected result CC] > 0,
"Gain",
IF ( Data[Expected result CC] < 0, "Loss" )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

This worked! THANK YOU! I needed to create some visuals for a meeting with my boss tomorrow and I can now create the correct ones. Really appreciate the help 🙂

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.