Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Creating an Updating Variable

Hello, 

I am trying to create a column that subtractrs from the previous calculated number (similar to an updating variable). I am getting confused on the DAX code.

 

Currently I have tried this but it did not work 

 

Improvements = 

VAR Total = Sum[table]

VAR NewTotal = Total - [Current Improvements]

 

Then I would like to update my total variable 

 

Total = NewTotal

Return 

Total 

 

 

 

 

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

 

You can use a Var to represent the result is the same:

Improvements = 
VAR Total = Sum[table] - [Current Improvements]
Return 
Total 

 

Best Regards,

Liu Yang

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

Greg_Deckler
Super User
Super User

@Anonymous Nope, VAR's are not variable, they are static. I know, confusing. You can have nested VAR's that are the same name so like:

Improvements = 

VAR Total = Sum[table]

VAR NewTotal = Total - [Current Improvements]
RETURN
  VAR Total = NewTotal
  RETURN Total

Sorry, probably confused you more.


@ 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...
Anonymous
Not applicable

Hi, 

I have tried this DAX instead, however, I keep getting an error with my index column I created in queary editory. 

 

HELP_PLS_0-1664445809295.png

 

Improvements =

DDBB[Total Column]
    - SUMX (
        FILTER (
            DDBB,
           DDBB[Index]< EARLIER(DDBB[Index])
        ),
        DDBB[Current Improvement1]
    )
 
 
 
Thanks!

 

@Anonymous Try:

Improvements =

SUM(DDBB[Total RPN Column])
    - SUMX (
        FILTER (
            DDBB,
           DDBB[Index]< EARLIER(DDBB[Index])
        ),
        DDBB[Current Improvement1]
    )

or maybe:

Improvements =
VAR __Index = MAX(DDBB[Index])
RETURN
SUM(DDBB[Total RPN Column])
    - SUMX (
        FILTER (
           ALL(DDBB),
           DDBB[Index]< __Index)
        ),
        DDBB[Current Improvement1]
    )

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

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.