Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
The following meaure will return the count of sales with sales greater than the overall average sales.
Calculate (Countrows(Sales), Filter (Sales, [Total]> AverageX(Sales, [Total]) ) )
how should i write the measure if I want the count of sales with total sales greater than the average sales of that particular category.
Solved! Go to Solution.
Hello @Cyriackpazhe
It would have been helpful if you had provided more clarifivation for your question, along with a sample dataset, a screenshot, or a dataset of the desired result you want.
However, as per my understanding of your query, I created a sample "Sales" dataset with categories in it, and I have used a single formula to calculate the count of sales that are above average.
When the categories are in context, it will calculate the sales that are above the category average, and when there is no context, it will calculate the number of sales that are above the overall sales average.
Here are the 3 DAX measures I have created:
The following DAX measure will just calculate the total sales:
Total Sales = SUM(Sales[Total])
The following DAX measure will simply calculate the average sales:
Average Sales = AVERAGE(Sales[Total])
The following DAX will calculate the count of sales that are above average. When a category is in context, it calculate the number of sales that are above the category average; otherwise, it will calculate the sales that are above the overall average.
Sales Above Avg =
VAR _category = SELECTEDVALUE(Sales[Category])
VAR _categoryAvg = CALCULATE([Average Sales], Sales[Category] = _category)
VAR _overallAvg = CALCULATE([Average Sales], ALL(Sales))
VAR _countAbvCatergoryAvg =
COUNTROWS(
FILTER(
Sales,
Sales[Category] = _category &&
Sales[Total] >= _categoryAvg
)
)
VAR _countAbvOverallAvg =
COUNTROWS(
FILTER(
Sales,
Sales[Total] >= _overallAvg
)
)
RETURN
IF(ISINSCOPE(Sales[Category]), _countAbvCatergoryAvg, _countAbvOverallAvg)
Here is the screenshot of the results for your reference:
Here is the screenshot of the main DAX measure:
I am also attaching the Power BI file for your reference.
Best Regards,
Udit
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍
🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
✨ Visit My Linktree: LinkTree
Hello @Cyriackpazhe
It would have been helpful if you had provided more clarifivation for your question, along with a sample dataset, a screenshot, or a dataset of the desired result you want.
However, as per my understanding of your query, I created a sample "Sales" dataset with categories in it, and I have used a single formula to calculate the count of sales that are above average.
When the categories are in context, it will calculate the sales that are above the category average, and when there is no context, it will calculate the number of sales that are above the overall sales average.
Here are the 3 DAX measures I have created:
The following DAX measure will just calculate the total sales:
Total Sales = SUM(Sales[Total])
The following DAX measure will simply calculate the average sales:
Average Sales = AVERAGE(Sales[Total])
The following DAX will calculate the count of sales that are above average. When a category is in context, it calculate the number of sales that are above the category average; otherwise, it will calculate the sales that are above the overall average.
Sales Above Avg =
VAR _category = SELECTEDVALUE(Sales[Category])
VAR _categoryAvg = CALCULATE([Average Sales], Sales[Category] = _category)
VAR _overallAvg = CALCULATE([Average Sales], ALL(Sales))
VAR _countAbvCatergoryAvg =
COUNTROWS(
FILTER(
Sales,
Sales[Category] = _category &&
Sales[Total] >= _categoryAvg
)
)
VAR _countAbvOverallAvg =
COUNTROWS(
FILTER(
Sales,
Sales[Total] >= _overallAvg
)
)
RETURN
IF(ISINSCOPE(Sales[Category]), _countAbvCatergoryAvg, _countAbvOverallAvg)
Here is the screenshot of the results for your reference:
Here is the screenshot of the main DAX measure:
I am also attaching the Power BI file for your reference.
Best Regards,
Udit
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍
🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
✨ Visit My Linktree: LinkTree
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
21 | |
15 | |
15 | |
11 | |
7 |
User | Count |
---|---|
25 | |
24 | |
12 | |
12 | |
11 |