Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
i have a measure to get "Avg cost" using it in my matrix :
Solved! Go to Solution.
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.
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.
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.
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.
Hi,
Share the download link of the PBI file. Is your FY from April to March?
A separate date dimensions table with a complete set of dates make time intelligence calculations easier.
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.
Sample calculations are in the attached pbix.
unfortunatly, this did not work either
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
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?
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
Let me check and get back.
much appreciated🙏
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
87 | |
81 | |
53 | |
37 | |
35 |