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
Anonymous
Not applicable

Running Total and calculating the average for the month/week based on running total.

Hello,

 

Trying to wrap my head around running totals and calculating averages from the running total on a per week/month/year basis.

 

Example Data Set:

Billing Code    QTY    Running Total    Transaction Date

A11101-Jan
A1-1002-Jan
A12203-Jan
A11304-Jan
A1101308-Jan

 

I have a transaction table showing a billing code 'A1' is being issued or returned based on the QTY. I have calculated the running total by creating a measure for this table.

 

Running Total = CALCULATE(Sum(TransactionTable['Qty'], FILTER( ALL('TransactionTable', 'TransactionTable'[TransactionDate] <= MAX('TransactionTable'[TransactionDate])

 

However, I don't know how to do another measure to average the running total on a per month/week/year basis.

 

Ex) If I were to average the Running total now, I should get 8.6.

1+0+2+3+13 / 5 = 8.6

I don't think this is what I want to do because it does'nt take into account the time period that A1 was deployed 13 times after January 8th and continued to be a value of 13 until January 31st.

 

I want to see:

 

Quantity    DeployedDate

101-Jan
002-Jan
203-Jan
304-Jan
305-Jan
306-Jan
307-Jan
1308-Jan
1309-Jan
1310-Jan
1311-Jan
1312-Jan
1313-Jan
1314-Jan
1315-Jan
1316-Jan
1317-Jan
1318-Jan
1319-Jan
1320-Jan
1321-Jan
1322-Jan
1323-Jan
1324-Jan
1325-Jan
1326-Jan
1327-Jan
1328-Jan
1329-Jan
1330-Jan
1331-Jan

 

Now with the average being 10.548 for the entire month of January.

 

What would be the best way to approach this problem?

 

1. I created my own Date Table and tried to do a running total with the given date attribute from January 1, 2007 to September 7, 2010 but the performance was really slow. I don't think it could even calculate the running total on this daily interval. Should even consider trying to get a running total on a per day basis from 2007?

Note that I do not want running total to reset per year. I need to it to calculate from the beginning of time and therefore use the ALL() in my filter when calculating.

 

2. How do you create another measure that requires information from another measure? Ex. Getting the average from the running totals

 

Is there another approach to getting the average for running totals for deployed units/quantities?

 

Thanks!

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Tocreate a calculated column in date table and update the measure as below should be fine.

Week = WEEKNUM('date'[Date])
Running total = 
CALCULATE (
    SUM ( 'Table'[QTY] ),
    FILTER ( ALL ( 'date' ), 'date'[Date] <= MAX ( 'date'[Date] ) ),
    VALUES ( 'date'[Date].[Year] ),
VALUES ( 'date'[Date].[Month] ),
VALUES ( 'date'[Week])
)
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

3 REPLIES 3
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use VALUES function to get the running total on a per year basis.

Running total = 
CALCULATE (
    SUM ( 'Table'[QTY] ),
    FILTER ( ALL ( 'date' ), 'date'[Date] <= MAX ( 'date'[Date] ) ),
    VALUES ( 'date'[Date].[Year] )
)

To get the correct average as we excepted, please check the following steps as below.

1. Create a calculated column in date table.

qty = 
LOOKUPVALUE ( 'Table'[QTY], 'Table'[Transaction Date], 'date'[Date] )

2. Create the measure as below.

average = 
VAR k =
    FILTER ( 'date', 'date'[qty] <> BLANK () )
RETURN
    DIVIDE (
        CALCULATE ( SUMX ( 'date', [Running total] ), KEEPFILTERS ( k ) ),
        CALCULATE ( COUNT ( 'date'[qty] ), KEEPFILTERS ( k ) )
    )

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @Anonymous ,

 

Tocreate a calculated column in date table and update the measure as below should be fine.

Week = WEEKNUM('date'[Date])
Running total = 
CALCULATE (
    SUM ( 'Table'[QTY] ),
    FILTER ( ALL ( 'date' ), 'date'[Date] <= MAX ( 'date'[Date] ) ),
    VALUES ( 'date'[Date].[Year] ),
VALUES ( 'date'[Date].[Month] ),
VALUES ( 'date'[Week])
)
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thanks @v-frfei-msft for the response. I've played around with the sample you have uploaded (Thanks btw!) but I can't seem to get the average for the entire month.

 

I want the average to equate to 10.548 as this is the average deployment over the month.

(Averaging the running total for the entire month)

How do I achieve the average for the running total of the entire month?

 

The average 3.8 seems to only apply to the individual dates and their related running totals.

(1+0+2+3+13) / 5 = 3.8

 

To extend this, I need to be able to get an average on a per week/per month basis.

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.