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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
lanzarote5
Frequent Visitor

Total based on sequence

Hi all,

 

I have a dataset with a certain sequence. At every sequence point, I have a value added, and a value substracted. 

Now I would like to have a calculation based on this (Added-Substracted), but not only for the row, but also for previous rows in the sequence (where the sequence number is lower than in the current row). It should also only count this for the relevant Category.

 

So in the end I would like to achieve something like the column "Total value", which I could use in a visual.

 

CategorySequenceAddedSubstractedTotal value
A1505
A2418
A35310
A410812
B1202
B2819
B3568
B46410
B512220

 

I have no idea how to solve this. Especially how to calculate previous rows. I tried somethings like this in DAX:

 

Cumulative = 

    CALCULATE (
        SUMX ( Table1[Added]- Table1[Substracted]),
        FILTER (
            Table1,
            Table1[Sequence] <=Table1[Sequence]
                && ( Table1[Category] ) = ( Table1[Category]) 
) )

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @lanzarote5,

 

Try the formula below please.

Column =
CALCULATE (
    SUM ( Table1[Added] ) - SUM ( Table1[Substracted] ),
    FILTER (
        ALLEXCEPT ( 'Table1', Table1[Category] ),
        Table1[Sequence] <= EARLIER ( Table1[Sequence] )
    )
)

Total_based_on_sequence

 

Best Regards,

Dale

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

2 REPLIES 2
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @lanzarote5,

 

Try the formula below please.

Column =
CALCULATE (
    SUM ( Table1[Added] ) - SUM ( Table1[Substracted] ),
    FILTER (
        ALLEXCEPT ( 'Table1', Table1[Category] ),
        Table1[Sequence] <= EARLIER ( Table1[Sequence] )
    )
)

Total_based_on_sequence

 

Best Regards,

Dale

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

Great! That works well. 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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