I have a challenge in Power BI Desktop to model and display a line chart that shows multiple lines in the same visualization where the x,y pair consists of two measures. The X axis contains a measure Average weight and the y axis Price per Kilo. There is a Normal line chart displaying the optimal curve where as there are a number of projects displaying other curves in the same chart (as legends). Below you see the coordinates for the normal curve, while the project curves can have other x,y values. This is easy in Excel but not that easy in Power BI.
To make lines it seems that every x coordinate in Line chart must be in the same interval. Otherwise I only get points not separate lines. Maybe the line chart component is not suitable for showing this. I think scatter chart is more suitable but I don't think it can show lines between the points.
I hope some of you have solved this or may be have pbix file to share how this have been solved.
Regards Geir
Sample data:
| Avg weight | Price pr kg |
|------------|-------------|
| 100 | 129.39 |
| 500 | 63.65 |
| 1000 | 40.13 |
| 1500 | 33.41 |
| 2000 | 30.05 |
| 2500 | 27.53 |
| 3000 | 25.43 |
| 3500 | 23.582 |
| 4000 | 22.91 |
| 4500 | 22.322 |
| 5000 | 21.902 |
| 5500 | 21.734 |
| 6000 | 21.65 |
Plot example:
This is seems quite straightforward, although perhaps your actual data is more complex?
With Avg Weight and 2 data series in one Table, I can use Avg Weight as the X Axis and the 2 data series as Values to achieve something similar to your requirement:
Related
I am trying to do a trivial task with Power BI Desktop. I have the following kind of data
| Name | Min | Max | Average | Median |
|-------- |----- |------- |--------- |-------- |
| team A | 0 | 3,817 | 120 | 120 |
| team B | -10 | 1,050 | 25 | 89 |
| team C | 5 | 14,320 | 50 | 48 |
And I want to create my own horizontal line with pre-defined (Start, End) points to plot for each team name the values of the Min, Max, Average, Median. And I filter the team name to adjust the numbers and the visual accordingly.
So far I have done the following static approach
The example above is totally non-dynamic because every point on the line is set by me. Also if for example, I select Team B with a higher median than average then the above visual line does not change the position of the relative spheres (in the image I posted, I have placed average always higher than the median which is not true for all the teams).
Thus, I would like to know if there is any fancy and well-plotted way to represent those 4 descriptive measures for a team name in a horizontal line that will respond when I use a different team. As I have noted on the image attached, the card visuals change when I change the team name. But the spheres do not move across the line.
My desired output
For Team B
While for Team C
I literally don't know if this is feasible in Power BI apart from the static approach I already did. Thank you in advance.
Regards.
I have two tables (subject & category) that are both related to the same parent table (main). Because of the foreign key constraints, it looks like Power BI automatically created the links.
Simple mock-up of table links
I need to count the subjects by type for each possible distance range. I tried a simple calculation shown below for each distance category.
less than 2m =
CALCULATE(
COUNTA('Category'[Descr]),
'Subject'[Distance] IN { "less than 2m" }
)
However, the filter doesn't seem to apply properly.
I want...
+------+--------------+--------------+--+
| Descr| less than 2m | more than 2m | |
+------+--------------+--------------+--+
| Car | 2 | 1 | |
| Sign | 4 | 2 | |
+------+--------------+--------------+--+
but I'm getting...
+------+--------------+--------------+--+
| Descr| less than 2m | more than 2m | |
+------+--------------+--------------+--+
| Car | 3 | 3 | |
| Sign | 6 | 6 | |
+------+--------------+--------------+--+
It's just giving me the total count by type which is correct but isn't applying the filter by distance so I can break it down.
I'm sure this is probably really simple but I'm pretty new with DAX and I can't figure this one out.
I wish I could mark Kosuke's comment as an answer. The issue was indeed with having to enable cross-filtering. This can either be done clicking on the link on your model or using a function to temporarily enable the cross filter.
I have two line plots that come from a different columns in measurement formulas but both share the time axis.
This is the first plot:
The second one:
In this case the second plot is just a scaled version of the first one, but the principle remains the same, I´m not able to just drag and drop the values from both measurements into the same "valores" box, it just iverwrites:
How can I plot this two measurements on the same box?
Something like the stacked areas plot but without the offset.
This is my data:
And the expresion fot the measurements I´m using:
Medida = CALCULATE(sum(test_data[Percentage_By_Class]);filter(test_data;test_data[Date]=max(test_data[Date]));
ALLEXCEPT(test_data;test_data[Score]))/ CALCULATE(sum(test_data[Percentage_By_Class]);
filter(all(test_data);test_data[Date]=max(test_data[Date])))
Medida2 = CALCULATE(sum(test_data[Percentage_By_Class]);filter(test_data;test_data[Date]=max(test_data[Date]));
ALLEXCEPT(test_data;test_data[Score]))/ CALCULATE(1.3*sum(test_data[Percentage_By_Class]);
filter(all(test_data);test_data[Date]=max(test_data[Date])))
And a google drive link to download the used data in CSV format:
https://drive.google.com/file/d/1dEdUwwofv1OQ9rOGQMuyfYKO9_YJDTcl/view?usp=sharing
I don't think there's a nice built-in way to do this, but here's a possible workaround:
Create a new table for the legend which will be the Cartesian product of scores and measures.
Legend =
ADDCOLUMNS(
CROSSJOIN(VALUES(test_data[Score]), {1,2}),
"Legend", [Score] & [Value]
)
This table should like this:
| Score | Value | Legend |
|-------|-------|--------|
| A | 1 | A1 |
| C | 1 | C1 |
| B | 1 | B1 |
| A | 2 | A2 |
| C | 2 | C2 |
| B | 2 | B2 |
Now create a combined measure that switches between [Medida] and [Medida2]:
Combo =
IF(
SELECTEDVALUE(Legend[Value]) = 1,
CALCULATE([Medida], test_data[Score] in VALUES(Legend[Score])),
CALCULATE([Medida2], test_data[Score] in VALUES(Legend[Score]))
)
Then if you put Legend in the legend box and Combo in the values box, you should get a chart like this:
You can change the colors too if you want to visually group the lines.
I'm trying to rescale a dataset in using PowerBI Desktop. I've imported a dataset full of raw data, but I can't use row context together with an aggregate. I'm trying to accomplish this:
Data:
+---------+-----+
| Name | Bar |
+---------+-----+
| Alfred | 0 |
| Alfred | -1 |
| Alfred | 1 |
| Burt | 1 |
| Burt | 0 |
| Charlie | 1 |
| Charlie | 1 |
| Charlie | 0 |
+---------+-----+
Calculations:
Foo: = SUM(Bar) / COUNT(Bar) GROUP BY Name
Which would Generate this dataset:
+---------+-----+
| Name | Foo |
+---------+-----+
| Alfred | 0 |
| Burt | .5 |
| Charlie | .67 |
+---------+-----+
Final Calculation:
Score: = (#Foo - MIN(Foo)) / (MAX(Foo)-MIN(Foo))
The goal is to grade on a curve with a set of data. I can do it in excel, but was hoping that Power BI could handle all the heavy lifting.
At this point it might be easier to do it all in SQL before bringing it into PowerBI, but that would make it significantly less dynamic (with date filters and the like). Thanks for any insight you might have!
I think you're looking for the GROUPBY DAX function. https://support.office.com/en-us/article/GROUPBY-Function-DAX-d6d064b2-fd8b-4c1b-97f8-c6d03cdf8ad0
You then would GROUPBY on the Name field and proceed from there. If need to use the measure outside of a visual that groups by each Name (like show me the average score after applying the curve), then you'll need to wrap that in a calculate table where you include the names, your measure projected as a column, and then do your aggregates (min/max/average) over that calculated table.
I'm using XSL-FO to generate an account statement print out. The PDF is actually just a simple table with a simple header on every page. The difficulty is that I have to display transaction volumes per page, e.g.
Page 1
+------------------------------+-----------+-----------+---------------------+
| Text | Credit | Debit | Balance |
+------------------------------+-----------+-----------+---------------------+
| Previous month | | | (*1) 1000 |
| abc | 1000 | | 2000 |
| abc | | 500 | 1500 |
| abc | | 200 | 1300 |
| ... | | | |
| Carry over | (*2) 1000 | (*3) 700 | (*4) 1300 |
+------------------------------+-----------+-----------+---------------------+
Page 2
+------------------------------+-----------+-----------+---------------------+
| Text | Credit | Debit | Balance |
+------------------------------+-----------+-----------+---------------------+
| Previous page | (*2) 1000 | (*3) 700 | (*4) 1300 |
| abc | 1000 | | 2300 |
| abc | | 500 | 1800 |
| abc | | 200 | 1600 |
| ... | | | |
| Carry over | (*2) 2000 | (*3) 1400 | (*4) 1600 |
+------------------------------+-----------+-----------+---------------------+
Here are some explanations:
This is the previous month's balance. It's pre-calculated and well-known as an XSL variable. No problem with that, that's a regular header (only on the first page)
This value is calculated on a per-page basis. It sums up all credit amounts on the same page. I can't calculate that myself, as I don't know when XSL-FO will do the page break. So I imagine XSL-FO must do the calculation for me. The sum at the bottom of a page is the same as the value at the top of the subsequent page.
This value is the same as 2, only for debit amounts.
This value is just the last transaction's balance at the bottom of a page. That value is repeated at the top of the next page.
How can I do these calculations with XSL-FO?
See also this related question: How to display one or the other information depending on the page number in XSL-FO?
Try "table markers": http://www.w3.org/TR/xsl/#fo_retrieve-table-marker.
In XSLT for each row inject a marker with the sum. Then let the engine select a marker to substitute for the fo:retrieve-table-marker in table header or footer. The idea is that proper marker will be selected at rendering time depending on the marker's position on the page and #retrieve-position and #retrieve-boundary on the fo:retrieve-table-marker.
Unfortunately, (at the time when I answered this question, it's no longer true) fop doesn't implement <fo:retrieve-table-marker/> from what I have found out. Instead, this solution here worked for me:
How to display one or the other information depending on the page number in XSL-FO?
It involves creating a separate table outside of the <fo:flow/> that displays the table header using <fo:retrieve-marker/> elements.