Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
adii
Helper I
Helper I

Problem with legend and measure in plot

Hello 

 

I have a little problem with line chart and measure. 

I have plot with measure (sum of values) on Y Y axis  and when I put on legend name of country I see couple of line depends which country I chosen on slicer , so it's right . But when I want put on plot another measure (Average of values for all country ) I couldnt do that . 

so how solve that problem ? 

I see solve the problem . I can make a lot of separate measure( calculate ...., Filter =Spain... etc )  for each country but it will be tough, 

 

someone could help ? 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @adii ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1685337985817.png

Please try:

First create a new table like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc6xDcAwCETRXahdGDBJ2iRjWOy/hk1ko0txzZO+oHeSKkKF7jmu5CXlCTlQ3jmxLboqZZSo5CdRcUpblTWUqFRQorK8bvvDE+WrGkpUepH7AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Legend = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Legend", type text}, {"Value", Int64.Type}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Legend"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
    #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "Custom", each {_[Legend],"Average"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Legend", "Country"}})
in
    #"Renamed Columns"

vjianbolimsft_1-1685338019777.png

Then build relationship between the two tables:

vjianbolimsft_2-1685338081143.png

Create a slicer:

vjianbolimsft_3-1685338123862.png

 

Apply the measure to the line chart:

Measure = 
var _a = ALLSELECTED('Table'[Country])
return 
IF(SELECTEDVALUE(Legend[Custom])="Average",CALCULATE(AVERAGE('Table'[Value]),FILTER(ALL('Table'),[Year]=SELECTEDVALUE('Table'[Year]))),SUM('Table'[Value]))

Final output:

vjianbolimsft_4-1685338177987.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-jianboli-msft
Community Support
Community Support

Hi @adii ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1685337985817.png

Please try:

First create a new table like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc6xDcAwCETRXahdGDBJ2iRjWOy/hk1ko0txzZO+oHeSKkKF7jmu5CXlCTlQ3jmxLboqZZSo5CdRcUpblTWUqFRQorK8bvvDE+WrGkpUepH7AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Legend = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Legend", type text}, {"Value", Int64.Type}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Legend"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
    #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "Custom", each {_[Legend],"Average"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Legend", "Country"}})
in
    #"Renamed Columns"

vjianbolimsft_1-1685338019777.png

Then build relationship between the two tables:

vjianbolimsft_2-1685338081143.png

Create a slicer:

vjianbolimsft_3-1685338123862.png

 

Apply the measure to the line chart:

Measure = 
var _a = ALLSELECTED('Table'[Country])
return 
IF(SELECTEDVALUE(Legend[Custom])="Average",CALCULATE(AVERAGE('Table'[Value]),FILTER(ALL('Table'),[Year]=SELECTEDVALUE('Table'[Year]))),SUM('Table'[Value]))

Final output:

vjianbolimsft_4-1685338177987.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.