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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Hussein_charif
Helper IV
Helper IV

Running total average in matrix not working properly

i have a measure to get "Avg cost" using it in my matrix :

AVG Cost=
VAR MinDate =
    CALCULATE(
        MIN(ValTB[Date]),
        ALL(ValTB)
    )
VAR MaxDate =
    MAX(ValTB[Date])

RETURN
    CALCULATE(
    DIVIDE(
        SUM(ValTB[Cost]),
        SUM(ValTB[Quant]),
        0)
),
        FILTER(
            ALL(ValTB[Date]),
            ValTB[Date] >= MinDate &&
            ValTB[Date] <= MaxDate
        )
    )


in my matrix i have the rows:
Item, year, month, day. the measure should not take the start date in my date slicer to consideration to calculate the avg cost, only the end date, which works perfectly fine, but within my matrix, for example if i am checking the avg cost for the month of september in 2024 for an item, the avg cost for september is not correct, because it calculates the measure with the start date only being from the 1st day of 2024, not the first day in my table, since i am filtering under 2024.
for more clearance:

Screenshot 2025-01-10 154751.png
for the above item in september, it should be 113, but it is showing 137 because it is considering the start date as jan 1st 2024, without taking to consideration the previous years.
 
is there a way to fix this?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Hussein_charif 

 

Try this:

 

AVG Cost = 
VAR MinDate = MIN('ValTB'[Date])
VAR MaxDate = MAX('ValTB'[Date])

RETURN
CALCULATE(
    DIVIDE(
    SUM(ValTB[Cost]),
    SUM(ValTB[Quant]),
    0),
    FILTER(
        ALL(ValTB),
        ValTB[Date] >= MinDate &&
        ValTB[Date] <= MaxDate
    )
)

 

 When you choose to check data for September, it ignores previous dates and only considers data for September.

 

vnuocmsft_0-1736757492698.png

 

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Regards,

Nono Chen

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

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Hi @Hussein_charif 

 

Try this:

 

AVG Cost = 
VAR MinDate = MIN('ValTB'[Date])
VAR MaxDate = MAX('ValTB'[Date])

RETURN
CALCULATE(
    DIVIDE(
    SUM(ValTB[Cost]),
    SUM(ValTB[Quant]),
    0),
    FILTER(
        ALL(ValTB),
        ValTB[Date] >= MinDate &&
        ValTB[Date] <= MaxDate
    )
)

 

 When you choose to check data for September, it ignores previous dates and only considers data for September.

 

vnuocmsft_0-1736757492698.png

 

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Regards,

Nono Chen

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

Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.  Is your FY from April to March?


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

Hi @Hussein_charif 

A separate date dimensions table with a complete set of dates make time intelligence calculations easier.

danextian_2-1736518944286.png

You can see in the screenshot below that even when the year changes, the calculations from the previous periods are still being carried over to the current.

danextian_3-1736519059151.png

 

Sample calculations are in the attached pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

unfortunatly, this did not work either

hi @danextian,

i'll try this and let you know.
thanks

The problem with your measure is that the average calculation is applied to the whole date column only

 FILTER(
            ALL(ValTB[Date]),
            ValTB[Date] >= MinDate &&
            ValTB[Date] <= MaxDate
        )

 Now, you can't be applying that to the whole ValTB table  or you will get the same value for the whole table with respect to the columns in your variables like in the screenshot below

danextian_0-1736521253015.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I removed that context when re applying the measure, but it gave me a complete different set of values which are all incorrect

How did you remove the context? Where is it applied to? Can you please share a sanitzed copy  of your pbix?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
suparnababu8
Super User
Super User

Hi @Hussein_charif 

I think  your measure  does not consider the start date in your date slicer but only the end date.  Therfore, you could modify the measure to ignore the date slicer for the start date. try the below measure. 

AVG Cost =
VAR MinDate =
    CALCULATE(
        MIN(ValTB[Date]),
        ALL(ValTB))
VAR MaxDate =
    MAX(ValTB[Date])
RETURN
    CALCULATE(
        DIVIDE(
            SUM(ValTB[Cost]),
            SUM(ValTB[Quant]),0),
        FILTER(
            ALL(ValTB[Date]),
            ValTB[Date] >= MinDate &&
            ValTB[Date] <= MaxDate
        ),
        REMOVEFILTERS(ValTB[Date]))

 

Let me know if it works. Thanks

hi @suparnababu8 , this returned the same exact values as my prev measure

Let me check and get back.

much appreciated🙏

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.