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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.