PowerBI新手求助:如何将指定表格转换为堆叠条形图
Power BI新手友好版:宽表转堆叠条形图教程
Hey there! No worries at all—we all start somewhere with Power BI 😊. Let's walk through exactly how to turn your table into the stacked bar chart you want, step by step.
第一步:先把宽表转成长表(数据重塑)
Your current table is in a "wide" format (each question is a separate column), but stacked bar charts work best with "long" data. We'll fix this using Power Query:
- 打开Power Query编辑器
- 在Power BI Desktop中,选中你的原始表格,点击顶部菜单栏的Transform data按钮,进入Power Query界面。
- 转置非ID列
- 选中
RespondentID列(按住左键点击列标题),右键点击它,选择Unpivot Other Columns。 - 这一步会自动把所有Question列转成两行:
Attribute(存储Question 1/2/3)和Value(存储对应的回答选项)。
- 选中
- (可选但推荐)重命名列
- 双击
Attribute列标题,改成Question;双击Value列标题,改成Response——这样字段名更直观,后续操作不容易搞混。
- 双击
- 保存更改
- 点击Power Query左上角的Close & Apply,回到报表视图。
第二步:创建堆叠条形图
Now your data is ready! Let's build the chart:
- 选择可视化类型
- 在右侧可视化面板里,找到并点击Stacked Bar Chart图标(就是那种横向的堆叠条形)。
- 配置字段
- 把
Question字段拖到Y轴区域(这会让左侧显示你的问题编号)。 - 把
Response字段拖到Legend区域(这会让不同的回答选项显示不同颜色)。 - 把
RespondentID字段拖到X轴区域,然后右键点击这个字段,选择Count(这样X轴就会显示每个选项的响应次数了)。
- 把
小优化建议(可选)
- 调整颜色:点击可视化面板的Format选项卡,找到Colors,可以给Disagree、Agree、Neither设置你偏好的颜色,让图表更清晰。
- 排序问题:如果
Question的显示顺序不对(比如不是1→2→3),右键点击Question字段,选择Sort by Column→Sort by Name,就能按顺序排列了。 - 显示数据标签:在Format选项卡中找到Data labels,打开它,就能看到每个堆叠块的具体计数,方便快速读取数据。
内容的提问来源于stack exchange,提问作者JDD
相关产品推荐
相关产品推荐

