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
crawfe
Helper I
Helper I

Distinct average by two categories

Hello. (sorry for the earlier incomplete post). I am new to power BI. I would like a measure to do a Distinct Average of a column using two (or more) categories for grouping.

 

ID         DATE                Type       Data1    Data2  Data3...etc.

1          01/01/2020         A            3            8

1          01/01/2020         B            5            2

1          01/01/2020         B            5            4

1          01/01/2020         B            5            3

1          01/01/2020         C            7            1

1          01/01/2020         C            7            2

2          01/01/2020         C            7            2

2          01/01/2020         C            7            1

etc...

I would like the Distinct AVG_ID_DATE measure to give: average for Data 1 (ID/Date/Type):

ID        DATE                AVG_ID_DATE

1          01/01/2020       5  (3+5+7)/3 

 

Thanks!

1 ACCEPTED SOLUTION

I tried the 2nd suggestion, it worked. Thanks!

To add a 3rd group_by category, just add it to the summarize table?

 

averageX(summarize(Table, Table[ID], Table[DATE],Table[Type],"_1", max(Table[Data1])),[_1])

View solution in original post

7 REPLIES 7
CNENFRNL
Community Champion
Community Champion

@crawfe I suggest transforming such a 2-dimensional into a 1-dimensional table in the first place, so that a versatile measure can be authored instead of specific Data1, Data2, ...

DS.png

 

Measure = AVERAGEX ( DISTINCT ( DS ), DS[Value] )

 

Table.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

That probably would simplify things (a simpler table). Thanks!

amitchandak
Super User
Super User

@crawfe ,

Try like

Averagex(union(distinct(Table2[Value]),distinct(Table2[Value])),[Value])

 

Can you share sample data and sample output in table format?

Sorry. See edited post above...I tried to clarify why I need distinct average...

@crawfe , Try as a new measure

 

averageX(values(Table[Type]), max(Table[Data1]))

or
averageX(summarize(Table,Table[DATE],Table[Type],"_1", max(Table[Data1])),[_1])

I tried the 2nd suggestion, it worked. Thanks!

To add a 3rd group_by category, just add it to the summarize table?

 

averageX(summarize(Table, Table[ID], Table[DATE],Table[Type],"_1", max(Table[Data1])),[_1])

Greg_Deckler
Super User
Super User

@crawfe Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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.

Top Solution Authors