Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi All,
I have this table about monthly sales value, however in case I draw an average line, the differences are really small, so I would like to show deviation from average in a different bar chart. I have already calculated the average monthly sales, which is annual sales/12. In the next step I have stucked. I need to calculate monthtly sales minus average sales and then put those into bar chart. How would you do that? I cannot add new column, because I have daily order data.
ChatGPT just gave this measure, but that does not work:
Monthlysales =
CALCULATE(
SUM('Pizza orders'[Ordervalue]),
ALLEXCEPT('Pizza orders', 'Pizza orders'[Month])
)
Thank you in advance for your help.
Hi @Pamiko ,
Thank you for reaching out to Microsoft Fabric Community.
Thank you @burakkaragoz @danextian @Ashish_Excel for the prompt response.
I want to check if you had the opportunity to review the information provided and resolve the issue.If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
Hey @Pamiko ,
I checked your message and also reviewed @Ashish_Excel 's reply in the forum. You’re very close, but I get why it’s confusing, especially when working with measures and not calculated columns.
Here’s how I’d approach it (I’ve dealt with similar pain in Power BI before):
Calendar Table is a must: Make sure you have a calendar/date table in your model, with at least columns for [Date], [Year], [Month Name] and [Month Number]. If you don’t have one, you can generate it in Power Query or with DAX.
Relationships: Your 'Pizza orders' table’s date column should be related to the [Date] column in your calendar table (single direction is fine).
Measures:
Total = SUM('Pizza orders'[Ordervalue])
Monthly Average = AVERAGEX( ALL('Calendar'[Month]), CALCULATE([Total]) )
Diff = [Total] - [Monthly Average]
Visual: In your bar chart, use [Month Name] from the Calendar table on the axis, and show the [Diff] measure as the value. That will let you see how much each month’s sales are above or below the average.
Extra tips:
Let me know if you hit any blockers, I can send more detailed screenshots or even a sample PBIX if needed.
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
Thank you for the detailed answer. Unfortunately I still have issues. Attaching picture:
Év = Year
Hónap = Month (sorry, I am working on my mother language as well).
My measures:
Hi @Pamiko ,
Thanks for sharing more details and your screenshot. Let’s clarify what’s happening and how you can fix it.
1. Why your Monthly Average isn’t working as expected:
Your current formula:
Monthly Average = AVERAGEX( ALL('Naptár'[Hónap]), CALCULATE([Totalsales]) )
This is calculating the average over all months, but if your [Totalsales] measure does not adjust for filter context correctly, it can either return the same value for every month, or sometimes the total value for all months.
2. The correct approach:
You want to get the average monthly sales (so, "total sales for the visible months" divided by "number of visible months"), and then for each month, subtract the average from that month's total.
Here’s a robust way to do it:
Total Sales:
Totalsales = SUM('Pizza orders'[Rendelesertek])
Monthly Average (per visible months):
Monthly Average = CALCULATE( [Totalsales], ALLSELECTED('Naptár'[Hónap]) ) / CALCULATE( DISTINCTCOUNT('Naptár'[Hónap]), ALLSELECTED('Naptár'[Hónap]) )
Deviation:
Diff = [Totalsales] - [Monthly Average]
3. What to check:
4. Important:
5. Practical test:
Try putting this new [Monthly Average] measure in a card visual. It should show the same number you’d get if you summed all visible months’ sales and divided by number of visible months. Each month’s [Diff] should tell you how much above or below average it is.
Let me know if this fixes it or if you see any odd numbers—happy to check your sample PBIX if you can share a dummy version!
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
Hi @Pamiko ,
Thanks for sharing more details and your screenshot. Let’s clarify what’s happening and how you can fix it.
1. Why your Monthly Average isn’t working as expected:
Your current formula:
Monthly Average = AVERAGEX( ALL('Naptár'[Hónap]), CALCULATE([Totalsales]) )
This is calculating the average over all months, but if your [Totalsales] measure does not adjust for filter context correctly, it can either return the same value for every month, or sometimes the total value for all months.
2. The correct approach:
You want to get the average monthly sales (so, "total sales for the visible months" divided by "number of visible months"), and then for each month, subtract the average from that month's total.
Here’s a robust way to do it:
Total Sales:
Totalsales = SUM('Pizza orders'[Rendelesertek])
Monthly Average (per visible months):
Monthly Average = CALCULATE( [Totalsales], ALLSELECTED('Naptár'[Hónap]) ) / CALCULATE( DISTINCTCOUNT('Naptár'[Hónap]), ALLSELECTED('Naptár'[Hónap]) )
Deviation:
Diff = [Totalsales] - [Monthly Average]
3. What to check:
4. Important:
5. Practical test:
Try putting this new [Monthly Average] measure in a card visual. It should show the same number you’d get if you summed all visible months’ sales and divided by number of visible months. Each month’s [Diff] should tell you how much above or below average it is.
Let me know if this fixes it or if you see any odd numbers—happy to check your sample PBIX if you can share a dummy version!
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
Another AI copy-paste without validation?
Since Total is a measure, it doesn't need to be wrapped in CALCULATE - it is implicitly applied.
This measure will not return the overall average for each month but simply the current month's value. It will at the total level.
Monthly Average =
AVERAGEX ( ALL ( Dates[Month Short] ), [Total Revenue] )
If you want the average to be applied to each month, modify the filter context by using CALCULATE
Monthly Average CALCULATE =
CALCULATE (
AVERAGEX ( VALUES ( Dates[Month Short] ), [Total Revenue] ),
ALLSELECTED ( Dates ) --applies to all visible rows only, use ALL to apply to the whole Dates
)
Hi,
Ensure that you create a Calendar table with calculated column formulas for Year, Month name and Month number. Sort the Month name by the Month number. Create a relationship (Many to One and Single) from the Date column of yoru Data table to the Date column of the Claendar table. To your visual, drag Year and Month name from the Calendar Table. Write these measures
Total = SUM('Pizza orders'[Ordervalue])
Monthly Average = averagex(allexcept(calendar,calendar[year]),[Total])
Diff = [total]-[monthly average]
If this does not work, then share the download link of the PBI file.
User | Count |
---|---|
84 | |
80 | |
70 | |
47 | |
43 |
User | Count |
---|---|
108 | |
54 | |
50 | |
40 | |
40 |