Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Just say I have a data table setup like the following:
Index | Month | Year | Parameter_Y | Value_Y |
1 | January | 2015 | Revenue | 100 |
2 | January | 2015 | Profit | 20 |
3 | January | 2015 | Expenses | 10 |
4 | January | 2015 | Tax | 10 |
5 | January | 2015 | Wages | 40 |
6 | February | 2015 | Revenue | 120 |
7 | February | 2015 | Profit | 57 |
8 | February | 2015 | Expenses | 11 |
9 | February | 2015 | Tax | 10 |
10 | February | 2015 | Wages | 42 |
I am trying to setup a R scatter plot to use the same table but with 2 slices of the parameter_Y column e.g. plot Revenue versus Profit. A fixed scatter plot can easily be prepared for say Revenue and profit, but I want the X and Y parameters to be dynamic.
I have tried using 2 tables (one a duplicate of the other). These tables have to be linked using the Index column otherwise Power Bi gives an error (Can’t determine relationships between the fields). When a Y parameter is selected, the 2nd table is automatically filtered such that only the Y parameter can be selected for X.
I can’t think of a way to pass the data for say Revenue and Profit through to R and make the process dynamic such that different combinations can be evaluated (e.g. Revenue versus expenses, profit versus tax etc.)
My R code is basic at the moment, and will look at making the chart fancier once I have resolved the data input issue:
library(ggplot2)
ggplot(dataset,aes(x=Value_X, y = Value.Y))+geom_point()
Has anyone worked out how to show a R scatter plot using 2 slicers for X and Y with data from one table?
Thanks in advance for your help!
Solved! Go to Solution.
I have further investigated my problem and have come up with a workable solution. I thought I should put it forward just in case anyone else has a similar problem.
I created a table that lists the slicer parameters such that the Parameter X values repeat for all parameter y values as indicated in the table below.
Parameter_X | Parameter_Y |
Revenue | Revenue |
Revenue | Profit |
Revenue | Expenses |
Revenue | Tax |
Revenue | Wages |
Profit | Revenue |
Profit | Profit |
Profit | Expenses |
Profit | Tax |
Profit | Wages |
The columns from the above table are fed into the R Scatter chart. Slicers are created for Parameter_X and Parameter_Y. This means the requires parameters are supplied to the Scatter chart code. The R code reads the required source data directly from a CSV file (using read.csv()). The X, Y data for the Scatter chart is filtered from the CSV data.
And now the Scatter chart reacts to variations in the selecter Parameter_X and Parameter_Y value.
I have further investigated my problem and have come up with a workable solution. I thought I should put it forward just in case anyone else has a similar problem.
I created a table that lists the slicer parameters such that the Parameter X values repeat for all parameter y values as indicated in the table below.
Parameter_X | Parameter_Y |
Revenue | Revenue |
Revenue | Profit |
Revenue | Expenses |
Revenue | Tax |
Revenue | Wages |
Profit | Revenue |
Profit | Profit |
Profit | Expenses |
Profit | Tax |
Profit | Wages |
The columns from the above table are fed into the R Scatter chart. Slicers are created for Parameter_X and Parameter_Y. This means the requires parameters are supplied to the Scatter chart code. The R code reads the required source data directly from a CSV file (using read.csv()). The X, Y data for the Scatter chart is filtered from the CSV data.
And now the Scatter chart reacts to variations in the selecter Parameter_X and Parameter_Y value.
Glad to hear that your issue got solved by youself, please accecp your reply as solutiom, as you said it will help other who have the similar issue to find the solution easily.
Regards,
Charlie Liao
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
95 | |
80 | |
68 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |