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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
thomasreick
Resolver I
Resolver I

Measure for colouring columns on a higher aggregation level than detailed data

Hi there I kindly request your help/hints on the follwing, because I am stuck somwhere in between...
I need to color a column chart based on the average out of X Months, whereas No of months is from a relative date slicer

The data are weekly based (Date of Sunday) and is counting number of contracts:

  • MyMeasure = Sum( MyTable[NoOfContracts] )

Using my datetable I am visualising MyMeasure in a columnchart
I wrote a measure to get the average per No of selected Months:

  • MyMonthlyAverage = AVERAGEX ( VALUES( calendar[MonthYear]), MyMeasure )

Based on the relation between MyMeasure and MyMonthlyAverage I want to decide the color of the column, "Geen" for above, "Red" for below MyMonthlyAverage.
Unfortunateley it seems that the number per Month (MyMeasure) is not divided by no of months but by the number of Sunday-dates in the selected period (e.g. MyMonthlyNoOfContracts / No of Sunday-Dates (52) and not MyMonthlyNoOfContracts / No of Months selected (12))

MyColumnColor =

var check = [MyMeasure]
var limit = [MyMonthlyAverage]
return SWITCH( TRUE(), check < limit, "Red", "Green")

Aways "Green" gets returned and so are the columns

 

Question: What is the Syntax to write a correct and proper MyMonthlyNumberOfContracts?

Appreciating your Input

 

thx in advance

Thomas

2 REPLIES 2
johnbasha33
Super User
Super User

@thomasreick 

To calculate the monthly average of the number of contracts correctly, you need to ensure that the calculation is based on the number of months selected in your slicer, rather than the number of Sunday-dates in the selected period. You can achieve this by modifying your measure to consider the number of months selected.

Here's how you can modify your measure to calculate the correct monthly average of the number of contracts:

MyMonthlyNumberOfContracts =
VAR SelectedMonths = CALCULATE( COUNTROWS( VALUES( Calendar[MonthYear] ) ) )
RETURN
DIVIDE( [MyMeasure], SelectedMonths, 0 )

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

Hi john basha33,
thank you very much fpr your input, but the returned value matches the value from this measure below

 

ØContractsMonthly =
var tbl = ADDCOLUMNS( VALUES( calendar[YYYYMM] ), "Contracts", [# Contracts]
return AVERAGEX( tbl, [# Contracts])
Your solutino (as mine) returns the Average valid for all periods selected

That seems fine.

 

So my question is not answered yet..., why is

 

MyColumnColor =

var check = [MyMeasure] 
var limit = [MyMonthlyAverage] (<= [MyMonthlyNumberOfContracts] <= [ØContractsMonthly])
return SWITCH( TRUE(), check < limit, "Red", "Green")

 

... alwyays returns green color as result for all columns although the bar height is obviously below or above reference line composed of limit-value....

 

Any suggestoins?

 

Your help is appreciated.

 

thx & brgds

Thomas

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.