google-chart linear regression with month on the x-axis - google-visualization

I have this scatter plot:
It's month-number. If I convert month to a number (1-12), I can calculate regression line like this:
Is there anyway to keep the month, not having to convert to number and still run linear regression?
Thanks!

Try leaving your scatter plot with the numbers for the x-axis, but customizing your tick labels to show months.
Add this to your options object.
hAxis:{ticks:[{v:1,f:'Jan'},{v:2,f:'Feb'},{v:3,f:'Mar'},{v:4,f:'Apr'},
{v:5,f:'May'},{v:6,f:'Jun'},{v:7,f:'Jul'},{v:8,f:'Aug'},
{v:9,f:'Sep'},{v:10,f:'Oct'},{v:11,f:'Nov'},{v:12,f:'Dec'}]}

Related

Problems calculating percentage of subtotals in PowerBI

I'm having problems with a line chart calculating the percentage of subtotals. What I have at the moment is as follows:
The PowerBI Data is structured similarly with a few extra columns.
I want to do a line graph where for each quarter, I have the percentage of each result for that quarter. For example, In Q4, between Business Unit A and B, I have 45 Passes, 2 Partial Passes, and 19 Fails. so of a total of 66, Q1 should show 68% pass, 3% partial pass, and 29% Fail. When I do the chart in Excel, I get the following (which is what I want to replicate in PowerBI):
In order to build this in PowerBI, I'm using a measure with the following formula:
Percentage = DIVIDE(SUM('TABLE NAME'[Number]),CALCULATE(SUM('TABLE
NAME'[NUMBER]),ALLEXCEPT('TABLE NAME'[DATE].[QUARTER])
When I use that formula, if I filter on an individual quarter, the chart values are correct, but when more than 1 quarter is displayed, the percentages are incorrect:
1 Quarter displayed:
Full Chart Displayed
The percentages between the chart in Excel and PowerBI are off when multiple quarters are displayed in PowerBI. I can't for the life of me figure out how to get the chart to be correct.
Any help would be tremendously appreciated.
Thanks!

How to create an avg measure in dax similar to the built-in chart function in Power BI?

I am trying to create an average measure that calculates/acts the same way as the Average line in the Clustered column chart does.
The avg calculated measure that I want to create should also be a straight line showing the average of the whole year and not on the monthly level as it does now. I cannot get it to ignore the month context like the built-in average line function for column chart.
This is what I have tried:
Avg. Quantity:=AVERAGEX(VALUES(Dim_Time[Year]),[Quantity])
and then place it in the Clustered column with lines chart in the line area values box. As you can see on the picture it doesn't produce the same result.
How would the dax logic need be written to replicate the same reslut as the built-in average line function ?
Best regards,
Rubrix
The core problem is the average measure you have written is being filtered by the month axis on your chart. You have to tell the measure to ignore that filter. Change cal[Month] to whatever your x-axis column is.
avg line = AVERAGEX(
ADDCOLUMNS(
SUMMARIZE(
ALLSELECTED(cal[Month]),cal[Month]),
"#qty",CALCULATE([Quantity])),
[#qty])

Scatter plot columns without aggregation in Power BI Desktop

After reading this thread on the official forums I still didn't see how to plot columns without aggregation, and that thread did not offer any working solution.
Is there a way in MS Power BI Desktop to simply plot one or more columns without any aggregation?
Imagine I just have a simple table, imported from csv, that has numerical values in two columns, and I want to plot those individual values in a scatter plot, which is one of the most elementary tasks possible and is simply done e.g. in Excel.
Is this not possible in Power BI Desktop?
To my surprise, this was certainly not trivial...
The only solution / workaround I found so far feels hacky, and probably doesn't scale up for too many datapoints. But here it is nonetheless.
For simple, small, whole-number datasets...
Suppose this dataset:
X;Y
1;2
1;2
1;4
3;4
4;1
1;2
4;1
2;1
Import that CSV and add a calculated column:
Label = "(" & [X] & ";" & [Y] & ")"
Now create the scatter plot with:
Legend set to Label
X Axis set to Average of X
Y Axis set to Average of Y
And you'll get this:
Not optimal, but at least it's a start for smaller datasets.
For simple, small, fractional number datasets...
The same process as above, and it'll look like this:
The legend is starting to break down and is probably best removed.
For larger datasets...
Suppose you have an Excel sheet with two columns X and Y, both with the formula =RAND() * 5. Copy paste this row to e.g. 500 rows, so you have many data points.
Load it up in PowerBI. Add the Label column like above. Add a scatter plot and drag Label to Details, and set X and Y to their respective axis. Here's the result:
It works pretty decently, I guess.

Putting a Regression Line When Using Pandas scatter_matrix

I'm using scatter_matrix for correlation visualization and calculating correlation values using corr(). Is it possible to have the scatter_matrix visualization draw the regression line in the scatter plots?
I think this is a misleading question/thought process.
If you think of data in strictly 2 dimension then a regression line on a scatter plot makes sense. But let's say you have 5 dimensions of data you are plotting in your scatter matrix. In this case the regression for each pair of dimensions is not an accurate representation of the global regression.
I would be wary presenting that to anyone as I can easily see where it could create confusion.
That being said if you don't care about a regression across all of your dimensions then you could write your own function to do this. A quick walk through of steps may be:
1. Identify number of dimensions N
2. Create figure
3. Double for loop on N, first will walk down rows, second will walk across rows
4. At each point add subplot, calculate regression (if not kde/hist position), plot scatter cloud and regression line or kde/hist

Google Chart Date X-Axis not proportionate to length of time

I have a simple chart plotting data over time. The data points are taken at random time intervals, and I would like the chart X axis (time) to actually reflect the interval between these dates. Currently the x axis always uses the same spacing between two dates, regardless of the span of time covering the delta.
Thanks!
https://developers.google.com/chart/interactive/docs/gallery/annotatedtimeline
should do what you want. It has support for graphing using dates.