The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello everyone,
I have a sample table (Table1) with three columns, X, Y, and Z, and let's say 20 rows from 1 to 20. In the Z column, the values are "Za" from row 1 to row 10, and "Zb" from row 11 to row 20.
I'm trying to create a Line chart with two curves:
- one curve of values in column Y vs. X for all Z values (20 rows).
- one curve of values in column Y vs. X for selectable Z values, either Za or Zb. This curve is plotted on the same visual with a thicker width and different colour with the first curve.
Would you please help advise how I can do it?
Thank you,
Adumio.
I have figured out a way to do it. I copied and pasted the visual, applied the slicer filter to only one visual (Format, Edit Interactions, None), made the background become transparent, put it in front of the first visual. The new measure is actually unnecessary. It could be done with the original measures of X and Y.
I still hope that someone can help me with a better way with just one visual.
Thank you.
Hello AnalyticsWizard,
Thanks you very much for your instructions. It's quick and detailed. The formula for Y_Selected_Z is definitely helpful.
However, there is still a hiccup. When I plot the chart, Y_All_Z curve was also filtered by the Slicer (see below).
Probably, the formula for Y_All_Z needs to be changed. I have tried the formula below but it didn't work.
Would you please suggest?
The data table is below.
X | Y | Z |
1 | 2 | Za |
2 | 4 | Za |
3 | 6 | Za |
4 | 8 | Za |
5 | 10 | Za |
6 | 12 | Za |
7 | 14 | Za |
8 | 16 | Za |
9 | 18 | Za |
10 | 20 | Za |
11 | 22 | Zb |
12 | 24 | Zb |
13 | 26 | Zb |
14 | 28 | Zb |
15 | 30 | Zb |
16 | 32 | Zb |
17 | 34 | Zb |
18 | 36 | Zb |
19 | 38 | Zb |
20 | 40 | Zb |
Below is the chart I made by Excel.
Thank you for your kind help,
Adumio.
To create a line chart with the specified requirements in Power BI, follow these steps. This solution involves creating measures for the overall data and for selectable Z values, then using these measures in a line chart visual.
Step 1: Create Measures
First, you'll need to create measures to calculate the Y values for both scenarios: one for all Z values and one for selectable Z values.
Measure 1: Y for All Z Values
This measure will represent the Y values across all Z values. Since you want all rows included, this could simply be the sum or average of Y, depending on what exactly you want to plot. If Y is just to be plotted as is, you might not need a measure for this, but here's how you could define an average:
```DAX
Y_All_Z = AVERAGE(Table1[Y])
```
Measure 2: Y for Selectable Z Values
This measure will be dynamic based on the selection of Z values (Za or Zb). You'll need to use a slicer for Z values to make them selectable. The measure will adjust based on the slicer selection:
```DAX
Y_Selected_Z = CALCULATE(AVERAGE(Table1[Y]), FILTER(Table1, Table1[Z] = SELECTEDVALUE(Table1[Z])))
```
Step 2: Add a Slicer for Z Values
1. From the Visualizations pane, add a **Slicer** to your report.
2. Drag the Z column from Table1 into the Field box of the slicer. This will allow you to select Za or Zb dynamically.
Step 3: Create the Line Chart
1. Add a **Line Chart** from the Visualizations pane.
2. Drag the X column to the Axis field.
3. Drag both measures (`Y_All_Z` and `Y_Selected_Z`) to the Values field. Power BI will automatically plot them as separate lines.
4. Adjust the formatting of each line under the Format pane to differentiate them. You can change the color and increase the stroke width of the `Y_Selected_Z` line to make it stand out as requested.
Step 4: Customize Your Chart
- Under the **Format** options of the line chart, you can find settings to adjust the line width, color, and add data labels for clarity.
- Ensure your slicer is clearly visible and instruct users that they can select Za or Zb to change one of the curves dynamically.
With these steps, you should have a line chart that plots all Y values against X for all Z values and another curve that dynamically changes based on the selection of Z values (Za or Zb) through the slicer, meeting the requirements described in your post.