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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors