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
SamFletch
Helper I
Helper I

Calculate a running total based on criteria

Hello all,

 

I'm relatively new to DAX and Powery Query and finally looking to dip my toes into a bit more advance features and I need some help.

 

I am running a simple report that looks at vehicle manufacturers, the age of the vehicle (in months) and the average cost of maintenance for that month. An example of the table I'm using is below:

 

Manufacturer Age In MonthsAverage Job Cost
Ford 1£100
Ford2£110
Ford3£100
Ford4£100
Mercedes1£80
Mercedes2£80
Mercedes3£60
Mercedes4£120
Fiat1£45
Fiat2£50
Fiat3£55
Fiat4£50

 

I have then created a measure within PowerBI to calculate a running total, which I've typed up as so:

 

Life Cost = 
CALCULATE(
    SUM(Sheet1[Average Job Cost]),
    FILTER(
        ALL('Sheet1'),
        'Sheet1'[Age in Months] <= MAX('Sheet1'[Age in Months])
    )
)

 

This gives me a running total for all costs:

image.png

 

Whilst this is handy, I really need to distinguish it further where I can see the running total not only for all manufacturers but for the individual ones as well. At present, when I add manufacturers to any of my visualisations, it they just show the same value for each rather than the different ones you would expect. 

 

image.png

 

I've added a column to the table to show more clearly what I mean.

 

Manufacturer Age In MonthsAverage Job CostLife Cost
Ford 1£100£100
Ford2£110£210
Ford3£100£310
Ford4£100£410
Mercedes1£80£80
Mercedes2£80£160
Mercedes3£60£220
Mercedes4£120£340
Fiat1£45£45
Fiat2£50£95
Fiat3£55£150
Fiat4£50£200

 

For what it's worth, Slicers do show the appropriate changes but I'm needing something that shows it all in one space rather than having to click through.

 

Hope I've made myself clear, thank you for the help.

1 ACCEPTED SOLUTION
littlemojopuppy
Community Champion
Community Champion

Hi @SamFletch 

Try this instead

Life Cost :=
CALCULATE (
    SUM ( Sheet1[Average Job Cost] ),
    FILTER (
        ALLEXCEPT ( 'Sheet1', Sheet1[Manufacturer] ),
        'Sheet1'[Age in Months] <= MAX ( 'Sheet1'[Age in Months] )
    )
)

 

littlemojopuppy_0-1609967191299.png

Hope this helps!  🙂

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Is the average job cost a measure that you have written?  Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@SamFletch ,  The information you have provided is not making the problem clear to me. Can you please explain with an example.
Try measure like

Life Cost = 
CALCULATE(
    SUM(Sheet1[Average Job Cost]),
    FILTER(
        allselected('Sheet1'),
        'Sheet1'[Age in Months] <= MAX('Sheet1'[Age in Months])
    )
)

 

 

Appreciate your Kudos.


@amitchandak I posted a response to this five hours ago with a screen shot showing that the solution I offered works.  Why did you feel that another solution was necessary???

littlemojopuppy
Community Champion
Community Champion

Hi @SamFletch 

Try this instead

Life Cost :=
CALCULATE (
    SUM ( Sheet1[Average Job Cost] ),
    FILTER (
        ALLEXCEPT ( 'Sheet1', Sheet1[Manufacturer] ),
        'Sheet1'[Age in Months] <= MAX ( 'Sheet1'[Age in Months] )
    )
)

 

littlemojopuppy_0-1609967191299.png

Hope this helps!  🙂

Thank you, this is exactly it!

 

I knew it would be something simple with the way I used "FILTER". 

 

Much appreciated for the quick and thorough response 🙂 

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.