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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
obesli
Frequent Visitor

Calculating cumulative values

 

 

I have data lite this table. Year mont column and sales amount in each mont. I would like to calculate mothly cumulative value, but I couldn't do it. IS there any method to propose?

 

Capture.JPG

 

 

1 ACCEPTED SOLUTION

Hi @obesli,


You can try to use below measures:

Spoiler
Cumulative = 
VAR _current =
    SELECTEDVALUE ( 'Table'[DateKey] )
VAR _previous =
    MAXX ( FILTER ( ALL ( 'Table' ), [DateKey] < _current ), [DateKey] )
RETURN
    IF (
        RIGHT ( VALUE ( _current ), 2 ) <> "01",
        SUMX (
            FILTER (
                ALL ( 'Table' ),
                [DateKey] < _current
                    && LEFT ( VALUE ( [DateKey] ), 4 ) = LEFT ( VALUE ( _current ), 4 )
            ),
            [Sales]
        ),
        MAX ( 'Table'[Sales] )
            + LOOKUPVALUE ( 'Table'[Sales], 'Table'[DateKey], _previous )
    )


Cumulative(Jan replace current + Previous Total) = 
VAR _current =
    SELECTEDVALUE ( 'Table'[DateKey] )
VAR _previous =
    MAXX ( FILTER ( ALL ( 'Table' ), [DateKey] < _current ), [DateKey] )
RETURN
    IF (
        RIGHT ( VALUE ( _current ), 2 ) <> "01",
        SUMX (
            FILTER (
                ALL ( 'Table' ),
                [DateKey] < _current
                    && LEFT ( VALUE ( [DateKey] ), 4 ) = LEFT ( VALUE ( _current ), 4 )
            ),
            [Sales]
        ),
        MAX ( 'Table'[Sales] )
            + SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[DateKey] <= _previous
                        && LEFT ( VALUE ( [DateKey] ), 4 ) = LEFT ( VALUE ( _previous ), 4 )
                ),
                [Sales]
            )
    )

Result:

11.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

8 REPLIES 8
Zubair_Muhammad
Community Champion
Community Champion

HI @obesli

 

You can use this calculated column

 

But this will Cumulate from all prior year.

Do you want accumulation to restart every year

 

=
CALCULATE (
    SUM ( [Total Sales] ),
    FILTER ( Table1, Table1[Year Month] <= EARLIER ( Table1[Year Month] ) )
)

Regards
Zubair

Please try my custom visuals

@obesli

 

You can try using this column if you Cumulative results to restart each year

 

=
CALCULATE (
    SUM ( [Total Sales] ),
    FILTER (
        Table1,
        LEFT ( Table1[Year Month], 4 ) = LEFT ( EARLIER ( Table1[Year Month] ), 4 )
            && Table1[Year Month] <= EARLIER ( Table1[Year Month] )
    )
)

 

 


Regards
Zubair

Please try my custom visuals

Hi,

 

Thank you for yoru reply. I did the second query and it works weel, but I need additional support.

I would like to summarize values before 201801 under 201801 and after 201901 under 201901.

 

How can I add such additional query?

 

Thanks,

 

Hi @obesli

 

Please could you show the desired results?


Regards
Zubair

Please try my custom visuals

I would like to show data like this.

 

 

Capture.JPG

HI @obesli

 

In that case you can add a colum to Group the periods

Then use this column for chart

For example

 

=
IF (
    Table1[Year Month] > 201901,
    "2019-2020",
    FORMAT ( Table1[Year Month], "General Number" )
)

Regards
Zubair

Please try my custom visuals

I did it, but this time there are same values in different rows and all off them calculated in the cumulative value. I need to take only row value and the other thing is in 201901 I need to add  the  201812  value to 201901.

 

How could I solve in the queries?

 

Capture.JPG

 

 

 

Capture1.JPG

Hi @obesli,


You can try to use below measures:

Spoiler
Cumulative = 
VAR _current =
    SELECTEDVALUE ( 'Table'[DateKey] )
VAR _previous =
    MAXX ( FILTER ( ALL ( 'Table' ), [DateKey] < _current ), [DateKey] )
RETURN
    IF (
        RIGHT ( VALUE ( _current ), 2 ) <> "01",
        SUMX (
            FILTER (
                ALL ( 'Table' ),
                [DateKey] < _current
                    && LEFT ( VALUE ( [DateKey] ), 4 ) = LEFT ( VALUE ( _current ), 4 )
            ),
            [Sales]
        ),
        MAX ( 'Table'[Sales] )
            + LOOKUPVALUE ( 'Table'[Sales], 'Table'[DateKey], _previous )
    )


Cumulative(Jan replace current + Previous Total) = 
VAR _current =
    SELECTEDVALUE ( 'Table'[DateKey] )
VAR _previous =
    MAXX ( FILTER ( ALL ( 'Table' ), [DateKey] < _current ), [DateKey] )
RETURN
    IF (
        RIGHT ( VALUE ( _current ), 2 ) <> "01",
        SUMX (
            FILTER (
                ALL ( 'Table' ),
                [DateKey] < _current
                    && LEFT ( VALUE ( [DateKey] ), 4 ) = LEFT ( VALUE ( _current ), 4 )
            ),
            [Sales]
        ),
        MAX ( 'Table'[Sales] )
            + SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[DateKey] <= _previous
                        && LEFT ( VALUE ( [DateKey] ), 4 ) = LEFT ( VALUE ( _previous ), 4 )
                ),
                [Sales]
            )
    )

Result:

11.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.