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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
yodha
Helper IV
Helper IV

How to calculate Rolling Cost?

Hi,

am very new to power bi.

i have Matrix in my .pbix like this,

 

and i want to calculate rolling cost, and final result should be like this,

 

Any help on this is much appreciated.

 

Thanks in Advance.

2 ACCEPTED SOLUTIONS
VijayP
Super User
Super User

@yodha 

You can use this function to get the cumulative.

I am sharing the PBIX which you can download form here

 

If you find this as solution please mentione this as solution and share your Kudos.

Also you can watch my Videos on www.youtube.com/perepavijay

Regards

Vijay Perepa

 

2020-04-27_131126.png




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


View solution in original post

v-yingjl
Community Support
Community Support

Hi @yodha ,

You can follow these steps to try:

1. I have created a calculated column to fomat date column for easy calculation:

 

Month-Year = VALUE(FORMAT('Table'[Date],"yyyymm"))​

 

2. I have created a measure to calculate present cost to replace previous column because I thought it was contradictory when calculating total cost basd on previous month:

 

Present cost measure =
VAR _minmonthyear =
    CALCULATE ( MIN ( 'Table'[Month-Year] ), ALLSELECTED ( 'Table' ) )
VAR _cmonthyear =
    SELECTEDVALUE ( 'Table'[Month-Year] )
VAR _lastmonthyear =
    CALCULATE (
        MAX ( 'Table'[Month-Year] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Month-Year] < _cmonthyear )
    )
RETURN
    IF (
        _cmonthyear = _minmonthyear,
        SUM ( 'Table'[Present cost] ),
        CALCULATE (
            SUM ( 'Table'[Present cost] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Categoary] ),
                'Table'[Month-Year] = _minmonthyear
            )
        )
            - CALCULATE (
                SUM ( 'Table'[Forecast cost] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Categoary] ),
                    'Table'[Month-Year] < _cmonthyear
                )
            )
    )
​

 

3. Finally, create a measure to calculate total cost:

 

Total cost = [Present cost measure]-SUM('Table'[Forecast cost])​

 

4. You will get the result like this:roll cost.png

Here is my sample file that hopes to help you, please try it: PBIX 

 

Best Regards,
Yingjie Li

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

3 REPLIES 3
v-yingjl
Community Support
Community Support

Hi @yodha ,

You can follow these steps to try:

1. I have created a calculated column to fomat date column for easy calculation:

 

Month-Year = VALUE(FORMAT('Table'[Date],"yyyymm"))​

 

2. I have created a measure to calculate present cost to replace previous column because I thought it was contradictory when calculating total cost basd on previous month:

 

Present cost measure =
VAR _minmonthyear =
    CALCULATE ( MIN ( 'Table'[Month-Year] ), ALLSELECTED ( 'Table' ) )
VAR _cmonthyear =
    SELECTEDVALUE ( 'Table'[Month-Year] )
VAR _lastmonthyear =
    CALCULATE (
        MAX ( 'Table'[Month-Year] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Month-Year] < _cmonthyear )
    )
RETURN
    IF (
        _cmonthyear = _minmonthyear,
        SUM ( 'Table'[Present cost] ),
        CALCULATE (
            SUM ( 'Table'[Present cost] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[Categoary] ),
                'Table'[Month-Year] = _minmonthyear
            )
        )
            - CALCULATE (
                SUM ( 'Table'[Forecast cost] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[Categoary] ),
                    'Table'[Month-Year] < _cmonthyear
                )
            )
    )
​

 

3. Finally, create a measure to calculate total cost:

 

Total cost = [Present cost measure]-SUM('Table'[Forecast cost])​

 

4. You will get the result like this:roll cost.png

Here is my sample file that hopes to help you, please try it: PBIX 

 

Best Regards,
Yingjie Li

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

Greg_Deckler
Super User
Super User

https://community.powerbi.com/t5/Quick-Measures-Gallery/Rolling-Months/m-p/391499#M124

https://community.powerbi.com/t5/Quick-Measures-Gallery/Rolling-Weeks/m-p/391694#M128

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
VijayP
Super User
Super User

@yodha 

You can use this function to get the cumulative.

I am sharing the PBIX which you can download form here

 

If you find this as solution please mentione this as solution and share your Kudos.

Also you can watch my Videos on www.youtube.com/perepavijay

Regards

Vijay Perepa

 

2020-04-27_131126.png




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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