如何在Power BI中统计两列数值并创建可视化效果?
Hey Karen, let's walk through how to validate your measure and build effective visualizations in Power BI based on what you've already started.
Your current measure:
Test Measure = COUNTA('Export'[Line])+COUNTA('Export'[Line 2])
uses COUNTA, which counts non-blank cells in each column. So this will give you the total number of non-empty entries across both Line and Line 2 columns. That works perfectly if your goal is to sum up all non-blank values from both columns—just keep in mind:
- If a single row has values in both
LineandLine 2, it will count as 2 towards the total - If you need to count unique values across both columns (instead of all non-blanks), you'll need to adjust the measure. Here's how:
Unique Combined Count = VAR CombinedValues = UNION(VALUES('Export'[Line]), VALUES('Export'[Line 2])) RETURN COUNTROWS(CombinedValues)
Now let's turn that measure into meaningful visuals—here are the most useful options based on common needs:
Option 1: Total Count Card (Quick Summary)
Great for highlighting the overall total at a glance:
- Drag a Card visual from the Visualizations pane onto your report canvas
- Find your
Test Measurein the Fields pane and drag it into the "Fields" well of the Card visual - Customize it: Add a title like "Total Non-Blank Entries (Line + Line 2)", adjust font size/color, or add a background to make it stand out
Option 2: Grouped Bar/Column Chart (Break Down by Category)
If you want to see how the total varies across different categories (e.g., a Region or Product column in your Export table):
- Drag a Clustered Column Chart or Clustered Bar Chart onto the canvas
- Drag your grouping column (e.g.,
Export[Region]) into the "Axis" well - Drag
Test Measureinto the "Values" well - Add data labels (via the Format pane > Data labels) to make the exact numbers visible, and tweak colors to match your report's style
Option 3: Side-by-Side Comparison (Individual Column Counts + Total)
If you want to show the separate counts for Line and Line 2 alongside their total:
- First create two additional measures for individual counts:
Line Count = COUNTA('Export'[Line]) Line2 Count = COUNTA('Export'[Line 2]) - Then choose one of these visuals:
- Stacked Column Chart: Drag your grouping column to Axis, then drag
Line CountandLine2 Countto Values. Add yourTest Measureas a separate card next to it for the total. - Matrix: Drag your grouping column to Rows, then drag all three measures (
Line Count,Line2 Count,Test Measure) to Values. This lets you see the breakdown and total in a single table-like view.
- Stacked Column Chart: Drag your grouping column to Axis, then drag
- Measure shows blank: Double-check that your
Exporttable has data, and that at least one of theLineorLine 2columns has non-blank values. Also check for any page/visual-level filters that might be excluding data. - Numbers don't match expectations: Remember that
COUNTAcounts empty strings ("") as non-blank. If you want to exclude those, replaceCOUNTAwith a filtered count, like:Line Count (Exclude Blanks) = COUNTROWS(FILTER('Export', 'Export'[Line] <> "" && NOT ISBLANK('Export'[Line])))
内容的提问来源于stack exchange,提问作者karen

