Forum Discussion

madhas's avatar
madhas
Frequent Visitor
3 years ago
Solved

Add the average per different category

I have a simple data model as below:

 

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?

 

5 Replies

  • madhas's avatar
    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. 

    • lbendlin's avatar
      lbendlin
      Super User

      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.