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
Dunner2020
Post Prodigy
Post Prodigy

Creating new column values based on previous rows value

Hi there,

 

I have a table that contains 3 columns (index, Waste Value, Running total of waste value). I want to create or populate new column/measure  (let say called Replaced Value) in such a way that if Running Total value (which is cumulative sum of 48 values of column named waste value) exceeds a certain threshold (let say 150), then it checks 48 past values of the column  'waste value'  and sees if the waste column value is greater than 10 then put 10 in Replaced value column otherwise copy the same value of 'waste value' column into Replaced Value column. Here is how the structure of the table looks like:

 

Date TimeWaste ValueRunning TotalReplaced Value
1/01/2000 0:002 2
1/01/2000 0:303 3
1/01/2000 1:004 4
1/01/2000 1:305 5
1/01/2000 2:006 6
1/01/2000 2:307 7
1/01/2000 3:008 8
1/01/2000 3:309 9
1/01/2000 4:000 0
1/01/2000 4:301 1
1/01/2000 5:002 2
1/01/2000 5:3013 10
1/01/2000 6:0014 10
1/01/2000 6:3016 10
1/01/2000 7:0011 10
1/01/2000 7:302 2
1/01/2000 8:002 2
1/01/2000 8:308 8
1/01/2000 9:009 9
1/01/2000 10:000 0
1/01/2000 10:304 4
1/01/2000 11:008 8
1/01/2000 11:309 9
1/01/2000 12:000 0
1/01/2000 12:3011 10
1/01/2000 13:002 2
1/01/2000 13:303 3
1/01/2000 14:004 4
1/01/2000 14:305 5
1/01/2000 15:006 6
1/01/2000 15:307 7
1/01/2000 16:008 8
1/01/2000 16:309 9
1/01/2000 17:0022 10
1/01/2000 17:303 3
1/01/2000 18:0021 10
1/01/2000 18:301 1
1/01/2000 19:002 2
1/01/2000 19:308 8
1/01/2000 20:007 7
1/01/2000 20:306 6
1/01/2000 21:005 5
1/01/2000 21:304 4
1/01/2000 22:003 3
1/01/2000 22:302 2
1/01/2000 23:009 9
1/01/2000 23:3062976
1/02/2000 0:0053005
1/02/2000 0:3043014
1/02/2000 1:0033003
1/02/2000 1:3063016
1/02/2000 2:0083038
1/02/2000 2:301130710
1/02/2000 3:001231110

 

For example, Running total value exceeds 150 when Date Time value is '1/01/2000 23:30'. To generate 'Replaced Value' column, it starts looking back 48 values of waste value column, if the value of the waste column is more than 10, then the value of Replaced Value column would be 10 (as shown in blue color) otherwise it would be same as the waste column is. I hope that clarifies the confusion. 

 

 
 

Could anyone guide me how can we do in power BI?

 

 

6 REPLIES 6
v-easonf-msft
Community Support
Community Support

Hi , @Dunner2020 

The calculation logic is still not clear.

Can your share more details about your excepted result?

And  it will be convenient   for us to understand  your  question  and check  the result of  our soulution.

 

Best Regards,
Community Support Team _ Eason

 

Hi @v-easonf-msft 

 

I have added the details about the expected result. Please let me know if it still not clear. Waiting for your positive reply.

Greg_Deckler
Super User
Super User

Sample source data as text would aid tremendously. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

That being said, dealing with previous values in rows generally involves variables or EARLIER. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

But how do we select the number of earlier observations? I have also added the sample data.

Question is not clear, But you can try like this. Both are new columns


Last Date Time = maxx(filter(table,table[Date Time]<earlier(table[Date Time])),table[Date Time])
Last value = maxx(filter(table,table[Date Time] =earlier(table[Last Date Time])),table[value])

Hi @amitchandak 

Sorry for the confusion, I have added more explanation. Hopefully that make sense now.

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.