[英]How to display data in area chart starting from the year chosen on a slicer and get all following years in Power BI
When choose a single Year on slicer I want area chart display all data from that chosen year and till the end (all years I have in my datasource). 当在切片器上选择单个Year时,我希望面积图显示从所选年份到结束的所有数据(我在数据源中拥有的所有年份)。 But instead it just displays me the data for single year choosing on a slicer. 但是相反,它只是在切片器上显示我一年的数据。 So I have this: 所以我有这个:
But I want it look like this: whatever Year I choose in slicer - chart will show all data starting from 2014 and goes till 2017. 但我希望它看起来像这样:无论我在切片器中选择的年份如何,图表都将显示从2014年到2017年的所有数据。
I am simply following a PowerBI template example and it seems like it's possible to do that: 我只是在遵循PowerBI模板示例,似乎可以这样做:
https://app.powerbi.com/view?r=eyJrIjoiMjc2NzExODItMjNhYy00ZWMxLWI2NGItYjFiNWMzYzUzMzhlIiwidCI6IjU3NGMzZTU2LTQ5MjQtNDAwNC1hZDFhLWQ4NDI3ZTdkYjI0MSIsImMiOjZ9 https://app.powerbi.com/view?r=eyJrIjoiMjc2NzExODItMjNhYy00ZWMxLWI2NGItYjFiNWMzYzUzMzhlIiwidCI6IjU3NGMzZTU2LTQ5MjQtNDAwNC1hZDFhLWQ4NDI3ZTdkYjI0MSIsImMiOjZ9
This is doable but it requires some tricks and extra measures. 这是可行的,但需要一些技巧和额外的措施。
TL;DR: The slicer you see is actually served as a value picker
, not as a filter. TL; DR:您看到的切片器实际上用作value picker
,而不用作过滤器。 An extra measure based on the value
is created and used as visual level filter
for the visual to do the trick. 将extra measure based on the value
创建一个extra measure based on the value
并将其用作visual level filter
以使视觉效果出色。
If you want to follow along, you can download the .pbix file from this Microsoft edX course about Power BI . 如果要继续学习,可以从此Microsoft edX课程中下载有关Power BI的.pbix文件 。
First, create a new table
based on the existing Date
table, with only distinct years: 首先,创建一个新table
基于现有的Date
表,只有不同的年代:
Year = DISTINCT('Date'[Year])
Then, create a slicer with the Year
column from the newly created Year
table ( NOT the Date
table). 然后,使用新创建的Year
表( 而非 Date
表)的Year
列创建切片器。
A measure (used as flag) is created as follows: 如下创建度量(用作标志):
Flag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) >= YearSelected, 1, 0)
So basically it gets the year selected from the year slicer and compare it with the year value in the date table to see if it's greater than or equal to it. 因此,基本上,它会从年份切片器中选择年份,并将其与日期表中的年份值进行比较,以查看该年份是否大于或等于它。
The chart is created with Year
column from the Date
table ( NOT the Year
table), and other needed measures. 该图表是使用Year
Date
表( 而非 “ Year
表)中的“ Year
列以及其他所需度量创建的。 Flag
is added to the Visual level filters
and set to 1. Flag
添加到Visual level filters
并将其设置为1。
So the Flag
value will change according to the value picked in the Year slicer, and served as the actual filter to the chart displayed. 因此, Flag
值将根据在Year切片器中选择的值进行更改,并用作显示图表的实际过滤器。
Results: 结果:
EDIT: on more use cases 编辑:更多用例
@Oleg Try to think of how you can apply the Flag
concept further. @Oleg尝试考虑如何进一步应用Flag
概念。 For example, if you want another chart displaying data of the same year as the slicer, you can set up another flag called SameYearFlag
and only change the part of value comparison to =
. 例如,如果希望另一个图表显示与切片器相同年份的数据,则可以设置另一个名为SameYearFlag
标志,并且仅将值比较的一部分更改为=
。 Add it to the chart Visual level filter
and it'll show only data in the same year. 将其添加到Visual level filter
图表中,它将仅显示同一年的数据。 Yes, by extension, that means you can have another flags like LastYearFlag
, NextYearFlag
, etc, as long as it makes sense to you. 是的,通过扩展,这意味着您可以拥有其他标志,例如LastYearFlag
, NextYearFlag
等,只要对您有意义。 The use case is up to you. 用例由您决定。
LastYearFlag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(YearSelected - VALUES('Date'[Year]) = 1, 1, 0)
NextYearFlag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) - YearSelected = 1, 1, 0)
SameYearFlag =
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) = YearSelected, 1, 0)
Examples: 例子:
By having only one year slicer, I can have charts with data in the same year, last year, next year and all years following, by applying different flags to them. 通过仅使用一年的切片器,我可以通过对它们应用不同的标记来获得具有同年,去年,明年以及随后的所有年的数据的图表。
As said, it's up to you to come up with more interesting use cases! 如前所述,由您自己提出更多有趣的用例!
I would propose to consider the new numeric range slicer. 我建议考虑使用新的数字范围切片器。 You can just set it as "Greater than or equal to". 您可以将其设置为“大于或等于”。 Users can select then the initial year in the range by entering the number or dragging the slicer. 用户可以通过输入数字或拖动切片器来选择范围内的初始年份。
You would need to enable this feature in Power Bi Desktop, Options under "Preview features". 您需要在Power Bi Desktop的“预览功能”下的“选项”中启用此功能。
Is well presented in the documentation https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-slicer-numeric-range/ 在文档https://powerbi.microsoft.com/zh-cn/documentation/powerbi-desktop-slicer-numeric-range/中很好地介绍了
This is how it could look like: 它看起来像这样:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.