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
Abhaykumar
Employee
Employee

Getting average of a measure and plotting as a trend line

I have a measure as following: 

 

Normalized Events = (IF ((COUNTROWS(FILTER('Events',[Type]="TypeA")) = 0), 0,COUNTROWS(FILTER('Events',[Type]="TypeA"))))/ COUNTROWS(FILTER('Population',[Type]="TypeA"))

 

This is plotted on a line chart with dates as x-axis. I also want to show a mean value as another line on the chart. How can i get the average of this measure as a single value that can be plotted as a horizontal line?

4 REPLIES 4
CheenuSing
Community Champion
Community Champion

@Abhaykumar

 

1. I created a scenario where in I have the sales data by date and there are more than 1 sales record for a day. This is called BaseSales

    

DateSales
2016030120
2016030130
2016030150
2016030425
2016030445
2016030440
2016030935
2016030955
2016040415
2016040434
2016040490
2016040445
2016040475
2016040440
20160420120
20160420130

 

2. The first step  is to get the averages by day and store it as a table created dynamically. 

3. To do this selecte new table from modelling and enter the code as follows

    AverageByDay(TableName) = Summarize( BaseSales, BaseSales[Date], "ByDayAverage",Average(BaseSales[Sales]))

4. What this actually does is creates an average by day from the base sales data and stores in the column ByDayAverage and stores the entire rows as table AverageByDay.

5. Create a mesaure AvgofAvg =Calculate(Average([ByDayAverage]),AllSelected(AverageByDay[Date]))

6. From this new table AverageByDay create the combo chart with Date as Shared Axis, ByDayAverage as ColumnValues and AvgofAvg as LineValues.

7. The chart will be the way you wanted.

 

Try it out and if you have any problems do reply to the post. Send me your mail id so that I can send you the pbix file.

 

If you find the solution working , please accept it as a solution and also give Kudos.

 

Cheers

 

 

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
v-caliao-msft
Employee
Employee

@Abhaykumar, You can add a calculated column using the same DAX expression , and then add this new column to Values.

Capture1.PNG
Capture.PNG

 

Regards,

Charlie Liao

@v-caliao-msft, I did the same thing but the average does not seem to be correct. As from the following screenshot, the average is 0.18 but when the column is plotted it shows average to be 0.20. I also added a second column with following DAX : 

AvgCol = AVERAGE(Event41[TestCol]). But this gives the same result of 0.20. Interestingly median also gives the same results.

 

2016-06-28 17_11_27-Img3.jpg

Anonymous
Not applicable

A bit of a guess here, but this sounds reasonable to me:

 

Median Event := MEDIANX(Calendar, [Normalized Events])

 

just drop this measure on your on your chart... maybe? 🙂

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.