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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
zdenek_moravec
Frequent Visitor

Hide average line in column chart when only one bar is displayed

Dear colleagues

I have a column chart with a date on x-axis and count of orders on the y-axis. I would like to display an average line over the bars, which displays an average value of the displayed bars values.

An easy solution is to switch to “clustered column chart”, which allows to enable average line on the “further analysis” tab. Everything looks good:

zdenek_moravec_3-1740471834667.png

until the x-axis shows only one period (one day, one month or one year). Then the avg line is distracting and actually useless:

zdenek_moravec_4-1740471953622.png

So my question is, how to set a column chart with an average line, which disappears, when the chart shows only one value/bar. 

See example AVG line in stacked column chart in case of one value.pbix.

I believe in a measure, which can detect number of periods displayed and which calculates the average of the bar values or sets the line value to blank based on count of displayed periods. One constrain is, that the date x-axis is managed by field parameters.

Thank You very much for any hint.

Zdenek Moravec

Cesky Krumlov, Czechia

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @zdenek_moravec ,

 

For this you need to create a measure with the following syntax:

Average Line = SWITCH(
			TRUE(),
			SELECTEDVALUE(DateParameters[DateParameters Order]) = 0 &&
			COUNTROWS(FILTER(
				SUMMARIZE(
					DIM_Calendar,
					DIM_Calendar[Date],
					"C", [CountOfOrders]
				),
				[C] <> BLANK()
			)) > 1,

        AVERAGEX(
				ALLSELECTED(DIM_Calendar[Date]),
				[CountOfOrders]
			),
			SELECTEDVALUE(DateParameters[DateParameters Order]) = 1&&
			COUNTROWS(FILTER(
				SUMMARIZE(
					DIM_Calendar,
					DIM_Calendar[Month],
					"C", [CountOfOrders]
				),
				[C] <> BLANK()
			)) > 1, AVERAGEX(
				ALLSELECTED(DIM_Calendar[Month]),
				[CountOfOrders]
			),
			SELECTEDVALUE(DateParameters[DateParameters Order]) = 2 &&
			COUNTROWS(FILTER(
				SUMMARIZE(
					DIM_Calendar,
					DIM_Calendar[Year],
					"C", [CountOfOrders]
				),
				[C] <> BLANK()
			)) > 1, AVERAGEX(
				ALLSELECTED(DIM_Calendar[Year]),
				[CountOfOrders]
			)
		, BLANK())

 

Then add the value has a constant line and not an average.

 

Be aware that you may need to recreate your chart from scratch since the creation of other line usually mess up the visual.

 

See file attach

MFelix_0-1740519271564.pngMFelix_1-1740519282512.pngMFelix_2-1740519299618.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @zdenek_moravec ,

 

For this you need to create a measure with the following syntax:

Average Line = SWITCH(
			TRUE(),
			SELECTEDVALUE(DateParameters[DateParameters Order]) = 0 &&
			COUNTROWS(FILTER(
				SUMMARIZE(
					DIM_Calendar,
					DIM_Calendar[Date],
					"C", [CountOfOrders]
				),
				[C] <> BLANK()
			)) > 1,

        AVERAGEX(
				ALLSELECTED(DIM_Calendar[Date]),
				[CountOfOrders]
			),
			SELECTEDVALUE(DateParameters[DateParameters Order]) = 1&&
			COUNTROWS(FILTER(
				SUMMARIZE(
					DIM_Calendar,
					DIM_Calendar[Month],
					"C", [CountOfOrders]
				),
				[C] <> BLANK()
			)) > 1, AVERAGEX(
				ALLSELECTED(DIM_Calendar[Month]),
				[CountOfOrders]
			),
			SELECTEDVALUE(DateParameters[DateParameters Order]) = 2 &&
			COUNTROWS(FILTER(
				SUMMARIZE(
					DIM_Calendar,
					DIM_Calendar[Year],
					"C", [CountOfOrders]
				),
				[C] <> BLANK()
			)) > 1, AVERAGEX(
				ALLSELECTED(DIM_Calendar[Year]),
				[CountOfOrders]
			)
		, BLANK())

 

Then add the value has a constant line and not an average.

 

Be aware that you may need to recreate your chart from scratch since the creation of other line usually mess up the visual.

 

See file attach

MFelix_0-1740519271564.pngMFelix_1-1740519282512.pngMFelix_2-1740519299618.png

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hello @MFelix , it works like a charm! I have to debug the DAX many times yet to fully understand, anyway Your solution is nice and easy. Thank You very much!

ChatGPT review for reference:

Key Components

  1. SWITCH(TRUE(), condition1, result1, condition2, result2, ...)

    • This structure evaluates multiple conditions and returns the corresponding result.
  2. SELECTEDVALUE(DateParameters[DateParameters Order])

    • Determines the current selection in the DateParameters table, which decides the granularity:
      • 0 → Daily
      • 1 → Monthly
      • 2 → Yearly
  3. Summarization with SUMMARIZE()

    • The measure ensures that there is more than one valid row before calculating an average.
    • The inner SUMMARIZE() groups data at the chosen level (Date, Month, or Year), retrieving the [CountOfOrders] measure.
    • The FILTER(..., [C] <> BLANK()) ensures that only non-blank values are considered.
  4. Averaging with AVERAGEX()

    • If conditions are met, AVERAGEX() calculates the average number of orders at the selected date level:
      • Daily: ALLSELECTED(DIM_Calendar[Date])
      • Monthly: ALLSELECTED(DIM_Calendar[Month])
      • Yearly: ALLSELECTED(DIM_Calendar[Year])
    • ALLSELECTED() ensures that only the currently selected values in the DIM_Calendar are considered.
  5. Default Case (BLANK())

    • If none of the conditions are met, the measure returns BLANK()

Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

"); $(".slidesjs-pagination" ).prependTo(".pagination_sec"); $(".slidesjs-pagination" ).append("
"); $(".slidesjs-play.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-stop.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-pagination" ).append(""); $(".slidesjs-pagination" ).append(""); } catch(e){ } /* End: This code is added by iTalent as part of iTrack COMPL-455 */ $(".slidesjs-previous.slidesjs-navigation").attr('tabindex', '0'); $(".slidesjs-next.slidesjs-navigation").attr('tabindex', '0'); /* start: This code is added by iTalent as part of iTrack 1859082 */ $('.slidesjs-play.slidesjs-navigation').attr('id','playtitle'); $('.slidesjs-stop.slidesjs-navigation').attr('id','stoptitle'); $('.slidesjs-play.slidesjs-navigation').attr('role','tab'); $('.slidesjs-stop.slidesjs-navigation').attr('role','tab'); $('.slidesjs-play.slidesjs-navigation').attr('aria-describedby','tip1'); $('.slidesjs-stop.slidesjs-navigation').attr('aria-describedby','tip2'); /* End: This code is added by iTalent as part of iTrack 1859082 */ }); $(document).ready(function() { if($("#slides .item").length < 2 ) { /* Fixing Single Slide click issue (commented following code)*/ // $(".item").css("left","0px"); $(".item.slidesjs-slide").attr('style', 'left:0px !important'); $(".slidesjs-stop.slidesjs-navigation").trigger('click'); $(".slidesjs-previous").css("display", "none"); $(".slidesjs-next").css("display", "none"); } var items_length = $(".item.slidesjs-slide").length; $(".slidesjs-pagination-item > button").attr("aria-setsize",items_length); $(".slidesjs-next, .slidesjs-pagination-item button").attr("tabindex","-1"); $(".slidesjs-pagination-item button").attr("role", "tab"); $(".slidesjs-previous").attr("tabindex","-1"); $(".slidesjs-next").attr("aria-hidden","true"); $(".slidesjs-previous").attr("aria-hidden","true"); $(".slidesjs-next").attr("aria-label","Next"); $(".slidesjs-previous").attr("aria-label","Previous"); //$(".slidesjs-stop.slidesjs-navigation").attr("role","button"); //$(".slidesjs-play.slidesjs-navigation").attr("role","button"); $(".slidesjs-pagination").attr("role","tablist").attr("aria-busy","true"); $("li.slidesjs-pagination-item").attr("role","list"); $(".item.slidesjs-slide").attr("tabindex","-1"); $(".item.slidesjs-slide").attr("aria-label","item"); /*$(".slidesjs-stop.slidesjs-navigation").on('click', function() { var itemNumber = parseInt($('.slidesjs-pagination-item > a.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); });*/ $(".slidesjs-stop.slidesjs-navigation, .slidesjs-pagination-item > button").on('click keydown', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); var itemNumber = parseInt($('.slidesjs-pagination-item > button.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); }); $(".slidesjs-play.slidesjs-navigation").on('click', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); }); $(".slidesjs-pagination-item button").keyup(function(e){ var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); $(".slidesjs-stop.slidesjs-navigation").trigger('click').blur(); $("button.active").focus(); } }); $(".slidesjs-play").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-stop").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-play")) { $(".slidesjs-stop").focus(); } } }); $(".slidesjs-stop").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-play").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-stop")) { $(".slidesjs-play").focus(); } } }); $(".slidesjs-pagination-item").keydown(function(e){ switch (e.which){ case 37: //left arrow key $(".slidesjs-previous.slidesjs-navigation").trigger('click'); e.preventDefault(); break; case 39: //right arrow key $(".slidesjs-next.slidesjs-navigation").trigger('click'); e.preventDefault(); break; default: return; } $(".slidesjs-pagination-item button.active").focus(); }); }); // Start This code is added by iTalent as part of iTrack 1859082 $(document).ready(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); $("#tip2").attr("aria-hidden","true").addClass("hidden"); $(".slidesjs-stop.slidesjs-navigation, .slidesjs-play.slidesjs-navigation").attr('title', ''); $("a#playtitle").focus(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").mouseover(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").blur(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#playtitle").mouseleave(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#play").keydown(function(ev){ if (ev.which ==27) { $("#tip1").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); $("a#stoptitle").focus(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").mouseover(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").blur(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").mouseleave(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").keydown(function(ev){ if (ev.which ==27) { $("#tip2").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); }); // End This code is added by iTalent as part of iTrack 1859082
Top Solution Authors