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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DAX query to add numbers until a condition is met

I have two columns named 'HA' and 'PA'. I want to add values in column 'HA' once it is greater than or equal to the value in 'PA'.

HA       PA

1.58     3.24

3.24     3.24

3.23     3.24

the values in column 'PA' will be the same. I want to add values in column 'HA' once the sum is greater than or equal to the value in column 'PA' For eg: it should add the first two rows (1.58 + 3.24 = 4.82) in column 'HA', as its sum will be greater than or equal to the value in columns 'PA'. It should not add the 3rd value in column 'HA'.

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Firstly, click query editor-> add columns-> add index column, then create a calculate column using DAX below:

Running Total = CALCULATE(SUM('Table'[HA]), FILTER('Table', 'Table'[Index] <= EARLIER('Table'[Index])))

1.PNG 

Then, create a measure as below:

Result = 
VAR Index = CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Running Total] = MIN('Table'[Running Total]) && 'Table'[Running Total] >= 'Table'[PA])) + 1
RETURN
CALCULATE(SUM('Table'[HA]), FILTER('Table', 'Table'[Index] <= Index))

2.PNG 

 

Community Support Team _ Jimmy Tao

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

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Firstly, click query editor-> add columns-> add index column, then create a calculate column using DAX below:

Running Total = CALCULATE(SUM('Table'[HA]), FILTER('Table', 'Table'[Index] <= EARLIER('Table'[Index])))

1.PNG 

Then, create a measure as below:

Result = 
VAR Index = CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Running Total] = MIN('Table'[Running Total]) && 'Table'[Running Total] >= 'Table'[PA])) + 1
RETURN
CALCULATE(SUM('Table'[HA]), FILTER('Table', 'Table'[Index] <= Index))

2.PNG 

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

@v-yuta-msft , Thank you for your help. 
Is there a way to create a Calculated column in place of this measure 'Result'?


@v-yuta-msft wrote:

@Anonymous ,

 

Firstly, click query editor-> add columns-> add index column, then create a calculate column using DAX below:

Running Total = CALCULATE(SUM('Table'[HA]), FILTER('Table', 'Table'[Index] <= EARLIER('Table'[Index])))

1.PNG 

Then, create a measure as below:

Result = 
VAR Index = CALCULATE(MAX('Table'[Index]), FILTER('Table', 'Table'[Running Total] = MIN('Table'[Running Total]) && 'Table'[Running Total] >= 'Table'[PA])) + 1
RETURN
CALCULATE(SUM('Table'[HA]), FILTER('Table', 'Table'[Index] <= Index))

2.PNG 

 

Community Support Team _ Jimmy Tao

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


 

Anonymous
Not applicable

Hi

 

are those columns of a table or measures?

Also, how do you choose values to sum? Are they sorted in some ways? 

I guess finally you want to have a MEASURE with the summed amount rather than a column?

 

In general, DAX cannot really work "iteratively" (i.e. do this until a condition is met) but you can achieve the same result in different ways. For example you could create a calculated column with the sum of the previous values (you'll need to RANK them in some ways, because DAX does not have the concept of "previous row") and then choose with a FILTER the row where the new value is higher than the value in PA.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors