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
GiantRectangle
Regular Visitor

Trouble with Running Total

Hi all,

What I'm trying to do is average [ACT Productivity] with matching [Code] for all dates less that or equal to the date for the selected item. Here's my data, where [**bleep** Productivity] is Is shown calculated correctly. I can't seem to get PBI to do this:

[Date Week Ending]       [Code]  [ACT Productivity] [**bleep** Productivity]

1/24/2021 0:00            3.86021.3096428571.309642857
2/14/2021 0:003.860210.889473686.099558269
1/9/2022 0:003.71122.5252.525
1/16/2022 0:003.71123.8333333333.179166667
2/27/2022 0:003.71229.8142857149.814285714
3/13/2022 0:003.74524.04531254.0453125
3/20/2022 0:003.74524.6330827074.339197604
4/17/2022 0:003.71122.1922.850111111
4/17/2022 0:003.712211.0333333310.42380952
4/17/2022 0:003.81122.4595041322.459504132
4/24/2022 0:003.71121.5639484982.528570458
4/24/2022 0:003.712211.3510.73253968
5/1/2022 0:003.71122.8189300412.586642374
5/1/2022 0:003.71223.048.809404761
5/1/2022 0:003.81121.3693693691.914436751
5/8/2022 0:003.71121.9053364272.473091383
5/8/2022 0:003.71223.5365853667.754840882
5/8/2022 0:003.81121.2751.701291167
5/8/2022 0:003.81222.22.2
5/15/2022 0:003.71123.3931252.604524757
5/15/2022 0:003.71123.881252.764115412
5/15/2022 0:003.71229.4160583948.031710467
5/15/2022 0:003.71428.3602941188.360294118
5/15/2022 0:003.81122.5161290321.905000633
5/15/2022 0:003.81122.5419354842.032387603
5/15/2022 0:003.81224.63.4
5/22/2022 0:003.71122.758620692.763504888
5/22/2022 0:003.712210.178.337180401
5/22/2022 0:003.71428.8882917478.624292933
5/22/2022 0:003.81124.4909090912.442141185
5/22/2022 0:003.81224.6753.825
5/22/2022 0:003.81428.6208333338.620833333

 

Here's the measure I've got:

**bleep** Productivity =
VAR MaxDate = MAX ( 'Date'[Date] ) -- Saves the last visible date
VAR ThisCode = SELECTEDVALUE( data[Code] ) -- Saves the code for the line
RETURN
CALCULATE (AVERAGE(data[ACT Productivity]), -- Average productivity
'Date'[Date] <= MaxDate,        -- Where date is before the last visible date
data[Code] = ThisCode,           -- Where code is the same as this line
ALL ( Date )                              -- Removes any other filters from Date
)

 

 

And here's a snip of the result. As you can see, [**bleep** Productivity] is coming through exactly the same as [ACT Productivity]:

GiantRectangle_0-1654102767369.png

What am I doing wrong?

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

hi @GiantRectangle 

please try

**bleep** Productivity =
VAR MaxDate =
    MAX ( 'Date'[Date] ) -- Saves the last visible date
RETURN
    CALCULATE (
        AVERAGE ( data[ACT Productivity] ),
        -- Average productivity
        'Date'[Date] <= MaxDate,
        -- Where date is before the last visible date
        ALLEXCEPT ( data, data[Code] ),
        -- Where code is the same as this line
        ALL ( Date ) -- Removes any other filters from Date
    )

View solution in original post

2 REPLIES 2
GiantRectangle
Regular Visitor

Thanks, tamerj1! That did it!

tamerj1
Super User
Super User

hi @GiantRectangle 

please try

**bleep** Productivity =
VAR MaxDate =
    MAX ( 'Date'[Date] ) -- Saves the last visible date
RETURN
    CALCULATE (
        AVERAGE ( data[ACT Productivity] ),
        -- Average productivity
        'Date'[Date] <= MaxDate,
        -- Where date is before the last visible date
        ALLEXCEPT ( data, data[Code] ),
        -- Where code is the same as this line
        ALL ( Date ) -- Removes any other filters from Date
    )

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.

Top Solution Authors