You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

折线图过滤数据点且不限制X轴范围,仅展示指定X轴值折线

Alright, let's figure out how to make your line chart behave exactly like you want—keeping the full hourly X-axis labels while only drawing the line for hours 21, 22, 23 when your slicer picks value 3. Here's the step-by-step fix, assuming you're working in Power BI (since you mentioned slicers):

Solution: Conditional Line Plot with Full X-Axis

1. Create a Filtered Measure Using DAX

The key here is to use a measure that returns values only for your target hours when the slicer is set to 3, and returns blank for all other cases. Blanks won't render on the line chart, so those segments won't appear.

Here's the DAX code you can adapt to your table names:

Filtered Inbound Value = 
VAR SelectedSlicer = SELECTEDVALUE('Slicer Table'[Your Slicer Column], 0)
VAR CurrentHour = SELECTEDVALUE('Hour Dimension Table'[Hour])
RETURN
    IF(
        SelectedSlicer = 3 && CurrentHour IN {21, 22, 23},
        SUM('Inbound Data Table'[Inbound Value]),
        BLANK()
    )
  • SelectedSlicer grabs the value you've picked in the slicer (the 0 is a fallback if nothing's selected)
  • CurrentHour targets the hour value currently being evaluated on the X-axis
  • The IF statement checks if both conditions are met: slicer is 3, and hour is 21/22/23. If yes, it calculates the sum of your inbound values; if not, it returns blank.

2. Set Up Your Line Chart

Now wire this measure into your chart:

  • Drag your Hour column (from your hour dimension table) into the X-axis well. Make sure this table includes all hours (0-23) you want displayed—this ensures the full X-axis labels stay visible even if there's no data for some hours.
  • Drag the Filtered Inbound Value measure you just created into the Y-axis well.
  • Keep your slicer connected to the same table you referenced in the measure.

3. Test the Behavior

When you select value 3 in the slicer, you'll only see the line plotted for hours 21, 22, 23. All other hour labels will still show up on the X-axis, but no line will be drawn for them. If you select any other value in the slicer, the measure returns blank, so no line will appear at all (you can adjust the IF condition if you want other slicer values to show full data—just tweak the logic to your needs).


内容的提问来源于stack exchange,提问作者Sid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:25:35