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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
madhas
Frequent Visitor

Add the average per different category

I have a simple data model as below:

madhas_1-1679061699305.png

 

and each table has following values:

Product Table:

 

Device NumberDesign Code
Prod-35282R6PM06
Prod-35283S6PM06
Prod-35284T6PM06
Prod-35285R6PM06
Prod-35286T6PM06
Prod-35713S6PM06
Prod-35714S6PM08
Prod-35715R6PM06
Prod-35716T6PM06
Prod-35717R6PM06
Prod-35718T6PM06

 

Result Table:

 

Device NumberK ValueZ ValueDate
Prod-352821100.4642.5642022-08-02
Prod-352831031.055.5212022-08-02
Prod-352841038.676-0.7222022-08-06
Prod-352851054.08-4.7532022-08-15
Prod-352861069.472.3122022-08-19
Prod-35713575.2425.6732022-09-01
Prod-35714612.123-5.4292022-09-12
Prod-35715593.50575.2732022-09-12
Prod-35716556.7040.3072022-09-15
Prod-35717593.948-2.1822022-09-17
Prod-35718564.9453.9732022-10-25

 

and Calendar Table:

 

DateYearMonthYearWeek
2022-08-02202282022-31
2022-08-02202282022-31
2022-08-06202282022-31
2022-08-15202282022-33
2022-08-19202282022-33
2022-09-01202292022-35
2022-09-12202292022-37
2022-09-12202292022-37
2022-09-15202292022-37
2022-09-17202292022-37
2022-10-252022102022-43

 

what I want to have in my report should look like this:

 

Device NumberK ValuerefK K value-refK
    
    
    
    
    
    
    

 

in which the refK is the average of all K values of the same design code.

I tried the following DAX formula to calculate the refK but it does not work:

 

refK = 
 VAR __avgKvalue=AVERAGE(Restult Table[K Value])  
 Return
 CALCULATE(
    AVERAGEX(__avgKvalue,
    FILTER(Product Table,
    VAR __CurrentDesignCode=Product Table[Design Code]
    Return
    Product Table[Design Code]=__CurrentDesignCode)
            )
          )

 

any ideas?

 

1 ACCEPTED SOLUTION

It does, but in a graphical way.  Here's the same as a measure.

 

lbendlin_0-1681219987926.png

 

View solution in original post

5 REPLIES 5
madhas
Frequent Visitor

@lbendlin Thanks. It works. May I ask why did you use MAX here? EARLIER was the first thing came to my mind, I used it but did not work. 

EARLIER is a leftover from the time before DAX had "variables" (which aren't really variable, but that's another story). MAX was chosen arbitrarily in this scenario, any aggregation would have worked. It all depends on what makes sense for the total.

madhas
Frequent Visitor

@lbendlin 

this doesn't deliver the needed report as I described in my post. 

It does, but in a graphical way.  Here's the same as a measure.

 

lbendlin_0-1681219987926.png

 

lbendlin
Super User
Super User

No need for code  - the data model can do the work.  see attached.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.