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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Niels_T
Post Patron
Post Patron

Measure: Accumulate value of previous month

Hello,

 

I've been trying to figure out this measure for the past couple days and I can't seem to find the solution:

 

 

Stock Niveau (Full) = 
IF( EOMONTH(MAX('Calendar'[Date]),0) = EOMONTH(TODAY(),0) ,



CALCULATE([Total Orders],DATESINPERIOD('Calendar'[Date], MAX('Calendar'[Date]),-3,MONTH)) + CALCULATE(SUM('Stock Value'[Cost Amount (Actual)]), ALL('Stock Value')) + SUM('Sales Forecast (GS)'[Sales FC aan COGS]),



IF( EOMONTH(MAX('Calendar'[Date]),0) > EOMONTH(TODAY(),0),

[Total Orders] + SUM('Sales Forecast (GS)'[Sales FC aan COGS])))

 

 

This measure works and gives me the following result (in sample data):

Niels_T_0-1649149141117.png

 

The last piece that is missing however, is the following:

Starting from the month after the current month, take the value of the month + the value of the previous month.

 

This is the expected result:

Niels_T_1-1649149219805.png

All months before current month have to be blank.

 

Someone knows how to figure this out?

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

Hi @Niels_T ,

 

There should be a [MonthNum] column in whole number format in Calendar table. You can try this code to create a virtul table and then sumx the result to get running total.

Running Total =
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Calendar' ),
        'Calendar'[Months],
        'Calendar'[MonthNum],
        "Stock Niveau (Full)",
            IF (
                EOMONTH ( MAX ( 'Calendar'[Date] ), 0 ) = EOMONTH ( TODAY (), 0 ),
                CALCULATE (
                    [Total Orders],
                    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -3, MONTH )
                )
                    + CALCULATE ( SUM ( 'Stock Value'[Cost Amount (Actual)] ), ALL ( 'Stock Value' ) )
                    + SUM ( 'Sales Forecast (GS)'[Sales FC aan COGS] ),
                IF (
                    EOMONTH ( MAX ( 'Calendar'[Date] ), 0 ) > EOMONTH ( TODAY (), 0 ),
                    [Total Orders] + SUM ( 'Sales Forecast (GS)'[Sales FC aan COGS] )
                )
            )
    )
RETURN
    SUMX (
        FILTER ( _SUMMARIZE, [MonthNum] <= MAX ( 'Calendar'[MonthNum] ) ),
        [Stock Niveau (Full)]
    )

 

Best Regards,
Rico 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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Niels_T ,

 

There should be a [MonthNum] column in whole number format in Calendar table. You can try this code to create a virtul table and then sumx the result to get running total.

Running Total =
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( 'Calendar' ),
        'Calendar'[Months],
        'Calendar'[MonthNum],
        "Stock Niveau (Full)",
            IF (
                EOMONTH ( MAX ( 'Calendar'[Date] ), 0 ) = EOMONTH ( TODAY (), 0 ),
                CALCULATE (
                    [Total Orders],
                    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -3, MONTH )
                )
                    + CALCULATE ( SUM ( 'Stock Value'[Cost Amount (Actual)] ), ALL ( 'Stock Value' ) )
                    + SUM ( 'Sales Forecast (GS)'[Sales FC aan COGS] ),
                IF (
                    EOMONTH ( MAX ( 'Calendar'[Date] ), 0 ) > EOMONTH ( TODAY (), 0 ),
                    [Total Orders] + SUM ( 'Sales Forecast (GS)'[Sales FC aan COGS] )
                )
            )
    )
RETURN
    SUMX (
        FILTER ( _SUMMARIZE, [MonthNum] <= MAX ( 'Calendar'[MonthNum] ) ),
        [Stock Niveau (Full)]
    )

 

Best Regards,
Rico Zhou

 

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

 

This was EXACTLY what I was looking for. 

 

Thank you!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.