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

How can I write a formula for incremental addition similar to += function?

I am trying to create f field that would show the consistency of the values per month but still can't figure it out. I'm fairly new at this and would appreciate the help!

 

Need to create a measure that calculates the Factor. If Previous month's value = 0 then Factor = Value, else Factor = +=1

 

For Example, for March, Factor= 1 since previous month's factor is zero. For April, Factor = 2 (prev month's factor +1) since the previous month's value is not zero.

 

MonthValueFactor
Jan00
Feb00
Mar21
Apr12
May13
Jun14
Jul00
Aug00
Sept21
Oct22
Nov00
Dec00

 

Thanks in advance

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

Hi @e9801591 

 

Please let me know if you'd like to get below results:

6.PNG

Method 1. Created the calculated column:

 

Column = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[date] <= EARLIER ( 'Table'[date] )
            && 'Table'[Value] <> 0
    )
)
Column 3 = 
VAR c = 'Table'[date]
VAR pre =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER ( 'Table', 'Table'[date] < c && 'Table'[Value] = 0 )
    )
RETURN
    IF (
        'Table'[Value] <> BLANK (),
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER (
                'Table',
                'Table'[date] <= EARLIER ( 'Table'[date] )
                    && 'Table'[Value] <> 0
            )
        )
            - CALCULATE ( MAX ( 'Table'[Column] ), FILTER ( 'Table', 'Table'[date] = pre ) )
    )

 

Method 2. 

Create the measure:

 

Measure = 
VAR c = MAX('Table'[date])
VAR pre =
 CALCULATE (
 MAX ( 'Table'[date] ),
 FILTER ( ALL('Table'), 'Table'[date] < c && 'Table'[Value] = 0 )
 )
RETURN
 IF (
 SUM('Table'[Value]) <> BLANK (),
 CALCULATE (
 COUNTROWS ( 'Table' ),
 FILTER (
 ALL('Table'),
 'Table'[date] <= MAX('Table'[date])
 && 'Table'[Value] <> 0
 )
 )
 -CALCULATE ( MAX ( 'Table'[Column] ), FILTER ( ALL('Table'), 'Table'[date] = pre ) )
 )

 

 

Pbix attached.

Community Support Team _ Dina Ye
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

6 REPLIES 6
v-diye-msft
Community Support
Community Support

Hi @e9801591 

 

Please let me know if you'd like to get below results:

6.PNG

Method 1. Created the calculated column:

 

Column = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    FILTER (
        'Table',
        'Table'[date] <= EARLIER ( 'Table'[date] )
            && 'Table'[Value] <> 0
    )
)
Column 3 = 
VAR c = 'Table'[date]
VAR pre =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER ( 'Table', 'Table'[date] < c && 'Table'[Value] = 0 )
    )
RETURN
    IF (
        'Table'[Value] <> BLANK (),
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER (
                'Table',
                'Table'[date] <= EARLIER ( 'Table'[date] )
                    && 'Table'[Value] <> 0
            )
        )
            - CALCULATE ( MAX ( 'Table'[Column] ), FILTER ( 'Table', 'Table'[date] = pre ) )
    )

 

Method 2. 

Create the measure:

 

Measure = 
VAR c = MAX('Table'[date])
VAR pre =
 CALCULATE (
 MAX ( 'Table'[date] ),
 FILTER ( ALL('Table'), 'Table'[date] < c && 'Table'[Value] = 0 )
 )
RETURN
 IF (
 SUM('Table'[Value]) <> BLANK (),
 CALCULATE (
 COUNTROWS ( 'Table' ),
 FILTER (
 ALL('Table'),
 'Table'[date] <= MAX('Table'[date])
 && 'Table'[Value] <> 0
 )
 )
 -CALCULATE ( MAX ( 'Table'[Column] ), FILTER ( ALL('Table'), 'Table'[date] = pre ) )
 )

 

 

Pbix attached.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
amitchandak
Super User
Super User

make sure you have date table join to date of you table, then you can try like

last MTD Sales = CALCULATE(SUM(Table[value]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

factor= if([last MTD Sales ]=0,1,last MTD Sales +1)

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you @amitchandak ! I see what you mean, but I don't think the formula checks all the preerquisites e.g. if the existing MTD sales > 0.

 

- if MTD sales =0 AND LM sales = 0;  then factor = 0

- if MTD sales >0 AND LM sales = 0; then factor = 1

- if MTD sales >0 and LM sales > 0; then factor= LM factor + 1

 

The formla provided below

factor= if([last MTD Sales ]=0,1,last MTD Sales +1)

 would return

- if MTD sales =0 AND LM sales = 0;  then factor = 1

 

Something like this

switch(true(),
[MTD sales] =0 && [LM sales] = 0, 0,
[MTD sales] >0 && [LM sales] = 0, 1,
[LM factor] + 1
)
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks @amitchandak 

 

created this

1. LM FACTOR = CALCULATE([FACTOR],PARALLELPERIOD('DATE TABLE'[Date],-1,MONTH),ALL('DATE TABLE'[Month],'DATE TABLE'[Month Name]))

 

2. FACTOR = switch(true(),

     [MTD]=0 && [LM]=0,0,
     [MTD]>0 && [LM]=0,1,
     [LM FACTOR]+1)

 

Applied these and this is how it looks like, with the values for Jun, Jul are incorrect

 JanFebMarAprMayJunJulAugSepOctNovDec
Person 1 - Factor001233301230

 

 

Reference data

 JanFebMarAprMayJunJulAugSepOctNovDec
Person 1 Value002111002200

 

Expected factor should be like this:

 JanFebMarAprMayJunJulAugSepOctNovDec
Person 1 Factor001234001200

Tried the following but I am not getting the correct factor

NameJanFebMarAprMayJunJulAugSepOctNovDec
Person 1002111002200

 

I have the following measures

1. LM - this is just 0 or 1. 0 if LM value = 0, 1 if LM value > 0 

2. MTD - this is just 0 or 1. If MTD value =0, 1 if MTD value > 0

3. Factor =if ([LM] = 0 && [MTD] = 0,0, if([LM]=0 && [MTD] >0,1, [LM]+1))

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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