Forum Discussion

Junaid11's avatar
Junaid11
Icon for Helper V rankHelper V
3 years ago
Solved

Subtract the column from a fixed value

Hello,
I have a below table:

DateEpenditureBudget
1/1/202323549800
1/2/202334 
1/3/20236786 
1/4/2023345 
1/5/202357 
1/6/202335 
1/7/202334 
1/8/202367 
1/9/202357 
1/10/202367 

I want to subtract expenditure from budget based on date starting from ascendingly and want to see how much budget is remaining.
My outcome will look like below:

DateEpenditureBudgetOutcome
1/1/2023235498007446
1/2/202334 7412
1/3/20236786 626
1/4/2023345 281
1/5/202357 224
1/6/202335 189
1/7/202334 155
1/8/202367 88
1/9/202357 31
1/10/202367 -36

YOUR HELP WOULD BE HIGHLY APPRECIATED.
THANK YOU

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Junaid11 ,

     

    Here is a measure that produces the precise table that you displayed in your question.

    Outcome = 
    VAR currentDate = 
    SELECTEDVALUE('Table'[Date])
    RETURN
        IF(
            HASONEVALUE('Table'[Date]),
            9800
               - CALCULATE(
                    SUM('Table'[Ependiture]),
                    'Table'[Date] <= currentDate,
                    ALLEXCEPT('Table','Table'[Date])
                )
            ,9800 - sum('Table'[Ependiture])
        )
    

     

     The outcome is showed in the below picture.

    There is a similar question which was answered by Chris Mendoza. Thanks for his contribution!
    You can look it up through this link: Solved: Subtract the value by fixed value to get next subt... - Microsoft Fabric Community

     

    Additional Tips:

    In the future, if you have a various range of budgets, you may consider using the following step.

     

    Go to Modeling ---- New Parameters ---- Numeric Range, and enter a range of numbers you would like to use as budget.


    And then change the measure to a new version:

    Outcome = 
    VAR currentDate = 
    SELECTEDVALUE('Table'[Date])
    VAR budget =
    SELECTEDVALUE('Table'[Budget])
    RETURN
        IF(
            HASONEVALUE('Table'[Date]),
            [Parameter Value]
               - CALCULATE(
                    SUM('Table'[Ependiture]),
                    'Table'[Date] <= currentDate,
                    ALLEXCEPT('Table','Table'[Date])
                )
            ,[Parameter Value] - sum('Table'[Ependiture])
        )
    

     

     

    Now the table will change if the parameter value changes.

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Junaid11 ,

     

    Here is a measure that produces the precise table that you displayed in your question.

    Outcome = 
    VAR currentDate = 
    SELECTEDVALUE('Table'[Date])
    RETURN
        IF(
            HASONEVALUE('Table'[Date]),
            9800
               - CALCULATE(
                    SUM('Table'[Ependiture]),
                    'Table'[Date] <= currentDate,
                    ALLEXCEPT('Table','Table'[Date])
                )
            ,9800 - sum('Table'[Ependiture])
        )
    

     

     The outcome is showed in the below picture.

    There is a similar question which was answered by Chris Mendoza. Thanks for his contribution!
    You can look it up through this link: Solved: Subtract the value by fixed value to get next subt... - Microsoft Fabric Community

     

    Additional Tips:

    In the future, if you have a various range of budgets, you may consider using the following step.

     

    Go to Modeling ---- New Parameters ---- Numeric Range, and enter a range of numbers you would like to use as budget.


    And then change the measure to a new version:

    Outcome = 
    VAR currentDate = 
    SELECTEDVALUE('Table'[Date])
    VAR budget =
    SELECTEDVALUE('Table'[Budget])
    RETURN
        IF(
            HASONEVALUE('Table'[Date]),
            [Parameter Value]
               - CALCULATE(
                    SUM('Table'[Ependiture]),
                    'Table'[Date] <= currentDate,
                    ALLEXCEPT('Table','Table'[Date])
                )
            ,[Parameter Value] - sum('Table'[Ependiture])
        )
    

     

     

    Now the table will change if the parameter value changes.

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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