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
siva3012
Helper II
Helper II

How to calculate an average line in the Line Chart ?

Hi, I want to calculate an average line for 3 days across the time interval period. I want to get an average Black line as shown in the below dig.  

error.png

 

 

 

 

Can anyone guide me with the solution.

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @siva3012,

 

Based on my test, if we have already add a legend for line chart, it is not allowed to add multiple columns or measures into values section. In other words, we can generate a measure to return average value, but we are unable to add this measure to line chart. 

 

As a workaround, we can create multiple measures to get result for each legend item separately.

 

Base on below sample data, we could create measures like:

1.PNG

Sum for 1 = CALCULATE(SUM('Table'[DurationDays]),FILTER('Table','Table'[ID]=1))
Sum for 2 = CALCULATE(SUM('Table'[DurationDays]),FILTER('Table','Table'[ID]=2))
Sum for 3 = CALCULATE(SUM('Table'[DurationDays]),FILTER('Table','Table'[ID]=3))

Average =
CALCULATE (
    SUM ( 'Table'[DurationDays] ),
    ALLEXCEPT ( 'Table', 'Table'[Type] )
)
    / CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        ALLEXCEPT ( 'Table', 'Table'[Type] )
    )

2.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

8 REPLIES 8
v-yulgu-msft
Employee
Employee

Hi @siva3012,

 

Based on my test, if we have already add a legend for line chart, it is not allowed to add multiple columns or measures into values section. In other words, we can generate a measure to return average value, but we are unable to add this measure to line chart. 

 

As a workaround, we can create multiple measures to get result for each legend item separately.

 

Base on below sample data, we could create measures like:

1.PNG

Sum for 1 = CALCULATE(SUM('Table'[DurationDays]),FILTER('Table','Table'[ID]=1))
Sum for 2 = CALCULATE(SUM('Table'[DurationDays]),FILTER('Table','Table'[ID]=2))
Sum for 3 = CALCULATE(SUM('Table'[DurationDays]),FILTER('Table','Table'[ID]=3))

Average =
CALCULATE (
    SUM ( 'Table'[DurationDays] ),
    ALLEXCEPT ( 'Table', 'Table'[Type] )
)
    / CALCULATE (
        DISTINCTCOUNT ( 'Table'[ID] ),
        ALLEXCEPT ( 'Table', 'Table'[Type] )
    )

2.PNG

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

How would you then add a filter on top of this to see just the average line and say "Sum for 1"?  Essentially filtering the measures?

@v-yulgu-msft : Thanks for the help. I also think this is the only way to approach. 

 

I have one query - How can i calculate the percentage between the Average line & other lines 1,2&3.

 

In simple words i want to know whether these values/lines (1,2&3) will be 5% +/- from the average line ?

 

Do you have any idea about it ?

 

Hi @siva3012,

 

Have you achieved your requirement? If yes, would you please mark the helpful reply as an answer or share your solution so that it can benefit more users?

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @siva3012,

 

Since the sum values and average values are all returned by measures, we can directly compute the percentage via:

 

Percentage1 = ([Sum for 1]-[Average])/[Average]

Percentage2 = ([Sum for 2]-[Average])/[Average]

Percentage3 = ([Sum for 3]-[Average])/[Average]

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @siva3012

 

Have you tried using adding an average line from Analytics pane?

 

AvgLine.JPGAvgLine2.png

@Anonymous : I tried the average line from Analytics plane and it draws an straingt line , i have shown it in the dig. 

Anonymous
Not applicable

Yeah, I missed that.. Let me try another way

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.