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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
nates05
Frequent Visitor

Running Total Difference between each Time Period

Hi, my data is below.

 

I generate data that is a running total of items sold ("Total Sold") per item and wanted to generate values that measures the difference between periods ("Sold per period"). For each item also, the earliest entry will be the initial value. May I ask how can I create a measure or caculated column for this? Will appreciate any help!

 

Annotation 2019-09-03 145802.png

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

Hi @nates05 ,

 

You can try my method:
At first, create a new column "rank".

rank =
RANKX ( 'Table', 'Table'[Period],, ASC, DENSE )

Then create your goal column.

Sold per period =
VAR a =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Total Sold], 1 ),
        FILTER (
            'Table',
            'Table'[Serial Codes] = EARLIER ( 'Table'[Serial Codes] )
                && 'Table'[rank]
                    = EARLIER ( 'Table'[rank] ) - 1
        )
    )
RETURN
    'Table'[Total Sold] - a

Here is the result.
2-1.PNG

 

Best Regards,

Eads

 

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

 

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

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi @nates05 ,

 

You can try my method:
At first, create a new column "rank".

rank =
RANKX ( 'Table', 'Table'[Period],, ASC, DENSE )

Then create your goal column.

Sold per period =
VAR a =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Total Sold], 1 ),
        FILTER (
            'Table',
            'Table'[Serial Codes] = EARLIER ( 'Table'[Serial Codes] )
                && 'Table'[rank]
                    = EARLIER ( 'Table'[rank] ) - 1
        )
    )
RETURN
    'Table'[Total Sold] - a

Here is the result.
2-1.PNG

 

Best Regards,

Eads

 

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

 

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

Hi, would this have an M code equivalent?

 

I realized I need to insert these columns in power query itself.

 

Thanks!

@v-eachen-msft that worked! thank you!

Greg_Deckler
Community Champion
Community Champion

Does the image posted represent source data or the expected output? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

You might find some of these links helpful, it is hard to say: 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...
https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

To clarify, the source data is columns up to "Total Sold" only, which is a running total of total items sold. I've attached a revised screenshote below. I wanted to calculate the actual sales per period which can be generated by the difference between each period

 

For example, for item V0000100001, between 3/31/2016 and 6/30/2016, actual sales were 44.

v1.png

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.