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
Anonymous
Not applicable

Average by Multiple Categories

Hello Power BI Community!

I would like some help calculating the average RTD using only the first two months of Poll data for each combination of Source Site and Destination.

Source Site.JPG

Example                                                                                                                           

ARC-BD-DHAKA-01-R-01 ➡ ARC-JP-OSAKA-01-R-01            ( 79.77 + 22.82 ) / 2    = 51.30

ARC-BD-DHAKA-01-R-01 ➡ ARC-JP-OSAKA-01-R-02            ( 256.12+258.09 ) / 2  = 257.11

ARC-BD-DHAKA-01-R-01 ➡ ARC-SG-SINGAPORE-01-R-01   ( 33.37 +9.53 ) / 2       =  21.45

 

Ideally the average RTD would be in the form of a column rather a measure, as this figure will be displayed in the row of the below matrix.

Matrix .JPG

Thank you for your help 😄 

@AllisonKennedy , @Greg_Deckler , @amitchandak , @Ashish_Mathur 

1 ACCEPTED SOLUTION

Hi,

These calculated column formulas work

First poll data for source site and destination combination = CALCULATE(MIN(Data[Poll Date]),FILTER(Data,Data[Source Site]=EARLIER(Data[Source Site])&&Data[Destination]=EARLIER(Data[Destination])))
2 month average RTD = CALCULATE(AVERAGE(Data[RTD]),FILTER(Data,Data[Source Site]=EARLIER(Data[Source Site])&&Data[Destination]=EARLIER(Data[Destination])&&EDATE(Data[First poll date for Source site and destination combination],1)>=Data[Poll Date]))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi Power Bi Community !

 

I require the solution to be in the form of a calculated column not a measure.

This what I am looking for.

 

Example Table

 

Source SiteDestinationPoll Date RTD2 Month Average RTD
DHAKAOSAKA-R-0131/07/201979.7751.3
DHAKA OSAKA-R-0131/08/201922.8251.3
DHAKA OSAKA-R-0130/09/2019122.2151.3
DHAKA OSAKA-R-0231/03/2020256.12257.11
DHAKA OSAKA-R-0230/04/2020258.09257.11
DHAKA OSAKA-R-0231/05/2020266.26257.11
DHAKA SINGAPORE-R-0131/07/201933.3721.45
DHAKA SINGAPORE-R-0131/08/20199.5321.45
DHAKA SINGAPORE-R-0130/09/201951.1221.45

 

Thanks  @ryan_mayu your measures work well. I just require a different format.

 

@Anonymous 

 

You can add another column in the table.

 

Column = 
AVERAGEX(FILTER(Sheet12,Sheet12[destination]=EARLIER(Sheet12[destination])&&Sheet12[Column2]<=2),Sheet12[RTD])

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,

These calculated column formulas work

First poll data for source site and destination combination = CALCULATE(MIN(Data[Poll Date]),FILTER(Data,Data[Source Site]=EARLIER(Data[Source Site])&&Data[Destination]=EARLIER(Data[Destination])))
2 month average RTD = CALCULATE(AVERAGE(Data[RTD]),FILTER(Data,Data[Source Site]=EARLIER(Data[Source Site])&&Data[Destination]=EARLIER(Data[Destination])&&EDATE(Data[First poll date for Source site and destination combination],1)>=Data[Poll Date]))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Here is another approach to do this as either a column or a measure

 

Measure - 

Avg RDT First Two Months =
CALCULATE (
AVERAGE ( RTD[RTD] ),
TOPN ( 2, VALUES ( RTD[Poll Date] ), RTD[Poll Date], ASC )
)

 

Calculated Column - 

Avg RDT First Two Months =
CALCULATE (
AVERAGE ( RTD[RTD] ),
ALLEXCEPT ( RTD, RTD[Source Site], RTD[Destination] ),
TOPN ( 2, VALUES ( RTD[Poll Date] ), RTD[Poll Date], ASC )
)

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ryan_mayu
Super User
Super User

@Anonymous 

 

Create a rank column and rank by destination.

 

rank = RANKX(FILTER(Sheet12,Sheet12[destination]=earlier(Sheet12[destination])),Sheet12[Polldate],,ASC)

 

1.png

Then create a measure calculate the average value based on the ranking.

 

Measure = CALCULATE(AVERAGE(Sheet12[RTD]),FILTER(Sheet12,Sheet12[rank]<=2))

 

2.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Greg_Deckler
Super User
Super User

@Anonymous - You should be able to get there using Lookup Min/Max https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

 

If that doesn't get you there, please post your data as text in a table. Thanks.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.