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
DataUser
Helper I
Helper I

Calculated Column - Every day, based on Previous Day Value

I'm looking to add/subtract two columns from present day with the value calculated on the previous day.  In Excel this is pretty simple but I can't do it there & input it in because one of my values that I want to add continuously is being calculated in the table. 

 

I have a fixed starting value. Then, I want to add Value A to it and subtract Value B. Value C is the finished value. For the next day, I want to replace that fixed starting value with the Value C from the previous day. Add a new value A and subtract a new value B and then I have a new Value C, and so forth.  Regardless of what the math is, the answer must be 300 or less than. So if it comes out more, I've been using "MIN" to replace it with 300.\

 

Any ideas for a formula? 

 

2021-12-14_13-25-40.jpg

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @DataUser 

 

Your problem can be solved by a few calculated columns.

Date2 = [Date]-1
N1 = [Fixed Initial Value]+[A]-[B]
N2 =
IF (
    CALCULATE (
        SUM ( 'Table'[N1] ),
        FILTER ( 'Table', [Date] <= EARLIER ( 'Table'[Date] ) )
    ) >= 300,
    300,
    CALCULATE (
        SUM ( 'Table'[N1] ),
        FILTER ( 'Table', [Date] <= EARLIER ( 'Table'[Date] ) )
    )
)
C = 
IF (
    CALCULATE (
        MAX ( 'Table'[N2] ),
        FILTER ( 'Table', [Date] = EARLIER ( 'Table'[Date2] ) )
    ) >= 300,
    300 + [A] - [B],
    [N2]
)

vzhangti_0-1639721202229.png

 

Best Regards,

Community Support Team _Charlotte

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

5 REPLIES 5
v-zhangti
Community Support
Community Support

Hi, @DataUser 

 

Your problem can be solved by a few calculated columns.

Date2 = [Date]-1
N1 = [Fixed Initial Value]+[A]-[B]
N2 =
IF (
    CALCULATE (
        SUM ( 'Table'[N1] ),
        FILTER ( 'Table', [Date] <= EARLIER ( 'Table'[Date] ) )
    ) >= 300,
    300,
    CALCULATE (
        SUM ( 'Table'[N1] ),
        FILTER ( 'Table', [Date] <= EARLIER ( 'Table'[Date] ) )
    )
)
C = 
IF (
    CALCULATE (
        MAX ( 'Table'[N2] ),
        FILTER ( 'Table', [Date] = EARLIER ( 'Table'[Date2] ) )
    ) >= 300,
    300 + [A] - [B],
    [N2]
)

vzhangti_0-1639721202229.png

 

Best Regards,

Community Support Team _Charlotte

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

DataUser
Helper I
Helper I

Here is the data and what I want to do in Excel form - I'm not sure how to do this in PowerBI. At most, C should equal 300. If the math comes out with a higher value, I would want it to cap off at "300". For my formula in Excel, it's simple: =MIN(300,"whatever the C value is from the day before"+"A" -"B"). 

 

 

DateFixed Initial ValueABC = This is what I want
1/1/2022100204116
1/2/2022 803193
1/3/2022 1206300
1/4/2022 4060280
ryan_mayu
Super User
Super User

@DataUser 

could you pls provide the sample data? 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




DataUser
Helper I
Helper I

I need to somehow keep that inital fixed value in. If I do it this way and reference the previous value A and B, I lose the initial 100. Is there a way to do this and include it? 

AntoineTRICHET
Resolver III
Resolver III

Hi @DataUser 

The function LOOKUPVALUE DAX (https://docs.microsoft.com/fr-fr/dax/lookupvalue-function-dax) can help you I think to get the data from the previous days & use it in your measure.
VAR Value_A_from_previous_date =
LOOKUPVALUE([column A], [column date], [column date]-1)
VAR Value_B_from_previous_date =
LOOKUPVALUE([column B], [column date], [column date]-1)
RETURN
MIN(Value_A_from_previous_date - Value_B_from_previous_date + [column A] - [column B], 300)

Please accept it as a solution if it solved your issue.

Have a nice evening

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.