Forum Discussion
Average not calculating cumulatively when selecting multiple months (quarter) or fiscal years
I have a table which shows the following
- QTY_TOTAL = total items delivered in the month
- NCR_QTY = total non-conforming items raised during the month
| FY | QUARTER_NUMBER | TR_MONTH | QTY_TOTAL | NCR_QTY | QUALITY_SCORE | MIN_DATE |
| FY2021 | Q1 | 04-Apr | 5 | 3 | 60.0% | 04-02-2020 |
| FY2021 | Q1 | 06-Jun | 1 | 3 | 300.0% | 06-25-2020 |
In my slicer, when I select Q1, instead of giving me an average of 100% (NCR_QTY = 6 / QTY_TOTAL = 6), it gives me 180% (360 / 2). So it does the average of the each month's score instead of dividing the sum of NCR_QTY by the sum of QTY_TOTAL.
My slicer is set in a custom hiarchy FY > QUARTER_NUMBER > TR_MONTH.
I need the matrix to show the correct averages.
I have searched and searched and can't find the answer how to achieve this.
Hi,
Please ensure that you have a Calendar table with calculated column formulas for Year, Month name, Month number and Quarter. Sort the Month name column by the Month number column. to any visual/filter/slicer, drag any date component from the Calendar table. Also, assuming qtY_total and ncr_qty are explicit measures which you have written, write this measure and drag it to a card visual
Average = divide([ncr_qty],[qty_total])
Hope this helps.
Hi RadTekno
I am not sure how your semantic model it setup but you need to tell dax to cumulatively run the average. Perpaps, your formula simply says average which only shows the average of what's been selected. Here's a sample DAX used in the image below.
Cumulative Txn Avg = VAR _table = FILTER ( ALL ( Dates ), Dates[Date] <= MAX ( Dates[Date] ) && Dates[Year] = MAX ( Dates[Year] ) ) RETURN CALCULATE ( AVERAGEX ( VALUES ( Dates[Month and Year] ), [Total Transactions] ), _table )Please see the attached pbix.
4 Replies
- Ashish_Mathur
Super User
Hi,
Please ensure that you have a Calendar table with calculated column formulas for Year, Month name, Month number and Quarter. Sort the Month name column by the Month number column. to any visual/filter/slicer, drag any date component from the Calendar table. Also, assuming qtY_total and ncr_qty are explicit measures which you have written, write this measure and drag it to a card visual
Average = divide([ncr_qty],[qty_total])
Hope this helps.
- danextian
Super User
Hi RadTekno
I am not sure how your semantic model it setup but you need to tell dax to cumulatively run the average. Perpaps, your formula simply says average which only shows the average of what's been selected. Here's a sample DAX used in the image below.
Cumulative Txn Avg = VAR _table = FILTER ( ALL ( Dates ), Dates[Date] <= MAX ( Dates[Date] ) && Dates[Year] = MAX ( Dates[Year] ) ) RETURN CALCULATE ( AVERAGEX ( VALUES ( Dates[Month and Year] ), [Total Transactions] ), _table )Please see the attached pbix.
- v-ssriganesh
Community Support
Hi RadTekno,
Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to danextian & Ashish_Mathur for sharing valuable insights.
Could you please confirm if your query has been resolved by the provided solutions? This would be helpful for other members who may encounter similar issues.
Thank you for being part of the Microsoft Fabric Community.
- v-ssriganesh
Community Support
Hello RadTekno,
Hope everything’s going great with you. Just checking in has the issue been resolved or are you still running into problems? Sharing an update can really help others facing the same thing.
Thank you.