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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.