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

Rolling average of increasing value

Hi all,

 

I am now on the Power BI front and I am looking for some tips on how to do the following:

 

My data set:

CarN-CarsMiles-days
BMW133
BMW244
FORD110
FORD240
FORD320
FORD433

 

I want to calculate the following:

CarN-CarsMiles-daysaverage miles-day / N-Cars
BMW13333
BMW24438.5
FORD11010
FORD24025
FORD32023.33333333
FORD43325.75

 

Then plot this in a line diagram with Miles- days on Y-Axis and averaged value on X-axis.

For BMW it would be (1,33) next point (2,38.5).

 

Is there anybody here that could help with this?

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

hi @joggis ,

 

you can create a calculated column like this:

average miles-day / N-Cars =
VAR _currentNCar =
    CALCULATE ( SELECTEDVALUE ( cars[N-Cars] ) )
VAR _currentCar =
    CALCULATE ( SELECTEDVALUE ( cars[Car] ) )
RETURN
    DIVIDE (
        CALCULATE (
            SUM ( cars[Miles-days] );
            FILTER ( ALL ( cars ); cars[Car] = _currentCar && cars[N-Cars] <= _currentNCar )
        );
        _currentNCar
    )

 

here is example I made using the data you have provided: pbix

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @joggis 

Is this problem sloved? 
If it is sloved, could you kindly accept it as a solution to close this case?
If not, please let me know.
 
Best Regards
Maggie
amitchandak
Super User
Super User

Try using the quick measure.

sturlaws
Resident Rockstar
Resident Rockstar

hi @joggis ,

 

you can create a calculated column like this:

average miles-day / N-Cars =
VAR _currentNCar =
    CALCULATE ( SELECTEDVALUE ( cars[N-Cars] ) )
VAR _currentCar =
    CALCULATE ( SELECTEDVALUE ( cars[Car] ) )
RETURN
    DIVIDE (
        CALCULATE (
            SUM ( cars[Miles-days] );
            FILTER ( ALL ( cars ); cars[Car] = _currentCar && cars[N-Cars] <= _currentNCar )
        );
        _currentNCar
    )

 

here is example I made using the data you have provided: pbix

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

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.