Scenario:
The user has the sample data as below, he needs to display the sum of Amount for each product in the clustered columns on first Y-axis. The second Y-axis should display the sum of Target Amount for each product in the bubbles/dots. X-axis is from Date field.
Sample data:
Expected result:
Detailed steps:
Analysis:
With the default line and clustered column chart, we only are able to display the bars for each legend product (P1, P2, P3 and P4) but not the pink dot (Target Amount). There is no suitable default visual and third part custom visual in Microsoft AppSource… We therefore create this chart using R scripts.
Preparation:
1. Install R and enable R visuals in Power BI Desktop (Please refer to this official documentation)
2. Install the libraries ggplot2 and dplyr
- Launch R console
- Type the below command to install the package
install.packages("ggplot2") install.packages("dplyr")
- Choose the CARN mirrors(please choose a mirror which is closer to your geographic location)
Create R visual
1. Select the R Visual icon in the Visualization pane to add an R visual and click “Enable” button when enabling script visuals window that appears.
2. Create a calculated column to get the YearMonth (Later it will be put on X axis of visual)
YearMonth = YEAR('Table'[Date])&"-"&"M"&MONTH('Table'[Date])
3. Drag the fields from the Fields pane that you want to consume in your R script in the Values section of the Visualization pane
4. Type the below scripts in R script editor
|
Finally, we get the results we want and are able to achieve these specific needs of the user.
Author: Yingying Ruan
Reviewer: Kerry & Ula
Dual Y axis values in one grouped column chart.pbix
Be the first to comment