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
nasbkrv
Regular Visitor

Previous row value formula

Hi Team,

I read this post: https://community.powerbi.com/t5/Desktop/Calculated-column-From-To-formula/td-p/1274376 and it works for me too, but not for every row.

The given example is:

nasbkrv_1-1596717453187.png


And the suggested formula is: From =
CALCULATE(SUM('Table'[Metric]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date]<EARLIER('Table'[Date])))+0
With this formula if the ID is the same, the “From’ column is zero for the first result and then it’s the same as “To” field. In my case I have two rows with the same ID, but on the same date (not different dates as in the example). If the ID is new, the From field should start again with 0. The result I’m looking for is:

nasbkrv_0-1596717436882.png

 



1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @nasbkrv ,

 

Please add an Index column in Power Query Editor first. And then, create calculated columns like so:

From =
CALCULATE (
    SUM ( 'Table'[Metric] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[ID] ),
        'Table'[Index] < EARLIER ( 'Table'[Index] )
    )
) + 0
To =
'Table'[From] + 'Table'[Metric]

from.PNG

 

Best Regards,

Icey

 

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

4 REPLIES 4
Icey
Community Support
Community Support

Hi @nasbkrv ,

 

Please add an Index column in Power Query Editor first. And then, create calculated columns like so:

From =
CALCULATE (
    SUM ( 'Table'[Metric] ),
    FILTER (
        ALLEXCEPT ( 'Table', 'Table'[ID] ),
        'Table'[Index] < EARLIER ( 'Table'[Index] )
    )
) + 0
To =
'Table'[From] + 'Table'[Metric]

from.PNG

 

Best Regards,

Icey

 

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

Hi @Icey ,

I'm testing the suggested formula but with a larger file and the system gives me an error that the file is too big and there is no enough memory. Any ideas if there is another formula or function except earlier which gives the same result?

Thank you.

amitchandak
Super User
Super User

@nasbkrv , In that you have to add an index column and try

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

 

Maxx(filter(table,[Index]=earlier([Index])-1),[Metric])

Greg_Deckler
Super User
Super User

@nasbkrv - Not 100% sure I understand but seems like you need an index column or something similar to identify previous rows. 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...

 

Also, since you are a New Member, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, 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

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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...

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.