Forum Discussion

Aluisjara86's avatar
Aluisjara86
New Member
4 years ago
Solved

Interation by rows applying a logical condition

What function can be used to interate row by row evaluating an expression and if a condition is applied, the value of the expression is added...

For Example: an account number(row data), with an amount that compared to the previous month gives a negative or positive variation (expression) , if la is < 0 (negative), add it up... So the result is only the  negatives added

  • Hi Aluisjara86 ,

     

    If you want to calculate the cumulative value of the measure, please try the formula:

     

    Cumulative Cur-Pre = 
    IF (
        [Cur-Pre] < 0,
        SUMX (
            FILTER (
                ALLSELECTED ( Dates[Month] ),
                [Cur-Pre] < 0
                    && Dates[Month] <= MAX ( Dates[Month] )
            ),
            [Cur-Pre]
        )
    )

     

    And if you want to calculate the cumulative value of the sales, please try the formula:

     

    Cumulative Sales = 
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALL ( Dates ), Dates[Month] <= MAX ( Dates[Month] ) && [Cur-Pre] < 0 )
    )

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • edhans's avatar
    edhans
    Community Champion

    Try this:

    SomeMeasure =
    CALCULATE(
        SUM( table[Column] ),
        Table[Column] < 0
    )
    
  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Aluisjara86 ,

     

    If you want to calculate the cumulative value of the measure, please try the formula:

     

    Cumulative Cur-Pre = 
    IF (
        [Cur-Pre] < 0,
        SUMX (
            FILTER (
                ALLSELECTED ( Dates[Month] ),
                [Cur-Pre] < 0
                    && Dates[Month] <= MAX ( Dates[Month] )
            ),
            [Cur-Pre]
        )
    )

     

    And if you want to calculate the cumulative value of the sales, please try the formula:

     

    Cumulative Sales = 
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALL ( Dates ), Dates[Month] <= MAX ( Dates[Month] ) && [Cur-Pre] < 0 )
    )

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.