cancel
Showing results 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

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):

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:

All months before current month have to be blank.

Someone knows how to figure this out?

1 ACCEPTED SOLUTION
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.

2 REPLIES 2
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.

Post Patron

This was EXACTLY what I was looking for.

Thank you!

Announcements

#### 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.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

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

Top Solution Authors
Top Kudoed Authors