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

Create Custom Column by using data from previous row

I am currently creating a CustomColumn in a existing model where I need to use data from previous rows to calucate the column value. This is already existing in Excel which I am currently migrating it to PowerBI.

 

In the screenshot shared below, "FinalResult" is a calculated column which uses a formula to calculate the result.

 

D5= IF(SUM(C3:C5)>=2,B5,"")

 

Since, it uses 2 previous rows to determine the value, the first 2 cells are empty and the formula starts only from D4 till end. Kindly let me know how do I create a similar column in PowerBI. 

 

Note: I already have the other 3 columns in model and only need to create "FinalResult"

 

CALCULATE.JPG

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

 

This calculated column formula seems to work

 

=if(CALCULATE(SUM(Data[Dependency]),FILTER(Data,Data[ID]>=EARLIER(Data[ID])-2&&Data[ID]<=EARLIER(Data[ID])))>=2,Data[TestResult],BLANK())

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Hi,

 

You have to go to Modelling > Add column and paste the query there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

 

This calculated column formula seems to work

 

=if(CALCULATE(SUM(Data[Dependency]),FILTER(Data,Data[ID]>=EARLIER(Data[ID])-2&&Data[ID]<=EARLIER(Data[ID])))>=2,Data[TestResult],BLANK())

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I am creating this model in PowerBI Desktop and can you help to write the same query accepted by PowerBI Desktop. I have trouble executing the query

Hi,

 

You have to go to Modelling > Add column and paste the query there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.