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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Calculating average in rows rather than as column

Hi there,

 

I have been searching for a solution to my problem, but unfortunately without luck.

 

My dataset consists of monthly prices for 4 companies. What I would like to do is to calculate the average of the 4 for each month, but NOT in a separate column.

 

Rather, I'd like the "benchmark" to be stored similarly to how the prices of the 4 companies are stored, as I'd like to show the benchmark next to each firm in my graphs, etc.

 

I am using PowerPivot for my further data analysis and to create PivotCharts. Preferably, the benchmark calculation should be done in PowerQuery (I am importing the actual datasets from MS Access), I'll take a PowerPivot solution instead if easier.

 

Any help is greatly appreciated. Unfortunately, I have not been able to enclose a sample workbook, but the image below is a screenshot of the file, and should clarify things.

 

Thanks!

 

Sample dataset.png

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @Anonymous , 

You could try below M code to see whether it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcyxDcAwDAPBXVQbsEU5WcZQm/1HiFURApsvvrhzDAtr+nQb9lXccvSLG8iNm5C7bzYv6EIuugC6KpT78AbdkIsuBF0Vyn0t8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Company = _t, Return = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Company", type text}, {"Return", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Return", each List.Average([Return]), type number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Company", each "Benchmark"),
    #"Appended Query" = Table.Combine({#"Added Custom", #"Changed Type"})
in
    #"Appended Query"

Best Regards,
Zoe Zhi

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

4 REPLIES 4
dax
Community Support
Community Support

Hi @Anonymous , 

You could try below M code to see whether it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZcyxDcAwDAPBXVQbsEU5WcZQm/1HiFURApsvvrhzDAtr+nQb9lXccvSLG8iNm5C7bzYv6EIuugC6KpT78AbdkIsuBF0Vyn0t8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Company = _t, Return = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Company", type text}, {"Return", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Return", each List.Average([Return]), type number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Company", each "Benchmark"),
    #"Appended Query" = Table.Combine({#"Added Custom", #"Changed Type"})
in
    #"Appended Query"

Best Regards,
Zoe Zhi

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

Anonymous
Not applicable

Thanks dax, works a charm

Greg_Deckler
Community Champion
Community Champion

Create a disconnected table with your firms and benchmarks and then make the right calculation depending on the category, either a firm or a benchmark. In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg, I get the idea of using a disconnected table, however, I cannot seem to make it work.

 

Any suggestions on how to build the measure for my specific case?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors