Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
In a line graph, I am showing the top 3 locations filtered based on another variable called 'location_score'. These top 3 locations are dynamic. That is what comes up as the top 3 locations will vary depending on the variable 'location_score'. In this line graph x-axis is Date and y-axis is location_score.
For each location, there are two lines. So for example the figure legend would look like this:
Melbourne - line1
Melbourne - line2
Sydney - line1
Sydney - line2
New Castle - line1
New Castle - line2
What I want to achieve is different line colours for different location but same line colour for 'line1' and 'line2' in the same location. So for example
Melbourne - line1 should be blue
Melbourne - line2 should be blue
Sydney - line1 should be green
Sydney - line2 should be green
New Castle - line1 should be red
New Castle - line2 should be red
How can this be achieved? Currently, as I refresh the data different colours come up and sometimes both Melbourne and Sydney would have the same colour making it difficult to distinguish which location is which.
Create Measures:
Color Scales:
Line Color =
VAR LocationName = [Location Name]
VAR LineType = [Line Type]
RETURN
IF(LineType = "line1",
SWITCH(LocationName,
"Melbourne", RGB(0, 0, 255), // Blue
"Sydney", RGB(0, 128, 0), // Green
"New Castle", RGB(255, 0, 0), // Red
RGB(192, 192, 192) // Default color for other locations
),
[Line Color] // Use the color defined for line1
)
Apply Color Measure:
Test and Refresh:
This approach ensures that the line colors are consistent for "line1" and "line2" within the same location, even as the top 3 locations change dynamically based on "location_score." You can easily customize the color logic by adjusting the DAX formula in the "Line Color" measure to fit your specific requirements.
User | Count |
---|---|
98 | |
75 | |
74 | |
49 | |
26 |