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
jc173
Frequent Visitor

Increment value with condition

Hi guys i have this situation:

1
0
1
1
1
0
1

I would like to get this,

11
00
12
12
12
00
13
13

Every time i have a 0 value i need to increment the value that i sum at the column.

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jc173 ,

Based on your questions, here are my answers.

Firstly, create a table as you mentioned.

vyilongmsft_0-1708412438396.png

Then go to the Power Query and select the Index Column.

vyilongmsft_1-1708412635680.png

Enter the appropriate DAX code to get the results you need.

 

Column = 
IF (
    'Table'[Column1] <> 0,
    RANKX ( FILTER ( 'Table', 'Table'[Column1] = 0 ), 'Table'[Index],,ASC ),
    0
)

 

vyilongmsft_2-1708413188238.png

 

 

Best Regards

Yilong Zhou

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

Hi @jc173 ,

Based on your questions, here are my answers.

Firstly, create a table as you mentioned.

vyilongmsft_0-1708412438396.png

Then go to the Power Query and select the Index Column.

vyilongmsft_1-1708412635680.png

Enter the appropriate DAX code to get the results you need.

 

Column = 
IF (
    'Table'[Column1] <> 0,
    RANKX ( FILTER ( 'Table', 'Table'[Column1] = 0 ), 'Table'[Index],,ASC ),
    0
)

 

vyilongmsft_2-1708413188238.png

 

 

Best Regards

Yilong Zhou

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

123abc
Community Champion
Community Champion

To achieve the desired result in Power BI using DAX, you can create a calculated column to track the cumulative sum based on the condition of encountering a 0 value. Here's how you can do it:

Assuming your table is named "Table1" and the column containing the original values is named "Value", you can follow these steps:

  1. Create a new calculated column by clicking on "Modeling" in the top menu, then selecting "New Column".

  2. Use the following DAX expression to create the calculated column:

CumulativeSum =
VAR CurrentValue = Table1[Value]
VAR CumulativeSum =
CALCULATE(
SUM(Table1[Value]),
FILTER(
ALL(Table1),
Table1[Value] <> 0 &&
Table1[Value] <= CurrentValue
)
)
RETURN
IF(Table1[Value] = 0, 0, CumulativeSum)

 

Explanation:

  • The VAR CurrentValue stores the current value of the row.
  • The VAR CumulativeSum calculates the cumulative sum of values that meet the conditions: not equal to 0 and less than or equal to the current value.
  • The IF function checks if the current value is 0. If it is, it returns 0; otherwise, it returns the CumulativeSum.

After creating this calculated column, you should see the desired result where the cumulative sum increments only when encountering a 0 value.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

jc173
Frequent Visitor

Hi thanks for the replie, but i'am on power bi online (Data FActory) and i don't have the possibility to insert a calculated column

123abc
Community Champion
Community Champion

If you're working in Power BI online or using Data Factory where you can't create calculated columns directly, you can achieve the desired outcome using DAX measures. Here's how you can do it:

Assuming you have a table named "YourTable" with a column named "Value" that contains your values, you can create a measure using DAX to compute the incremented values based on your condition.

Here's the DAX measure you can use:

 

Incremented Value =
VAR MaxRowIndex = MAX('YourTable'[Index])
VAR PrevIncrement =
CALCULATE(
MAX('YourTable'[Incremented Value]),
FILTER(
ALL('YourTable'),
'YourTable'[Index] < MaxRowIndex &&
'YourTable'[Value] = 0
)
)
RETURN
IF('YourTable'[Value] = 0, PrevIncrement + 1, PrevIncrement)

 

 

Make sure to replace 'YourTable', 'Index', 'Value', and 'Incremented Value' with the actual names of your table and columns.

This measure works as follows:

  • It finds the maximum index value for the current row.
  • It calculates the previous increment value based on the condition that the index is less than the current row's index and the value is 0.
  • If the value for the current row is 0, it increments the previous increment value by 1; otherwise, it returns the previous increment value.

You can then use this measure in your visuals to display the incremented values based on your condition.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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