Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Reference current filtered measure as a filter in another measure

Hello! I feel like this should be easy but I am new and stuck, your help is much appreciated!!!

 

I have a measure that calcuates the mode price (most recurring number) on a Sales fact table. I need to calculate the Average Units Sold when the Price Per Unit column equals the Mode Price based on the filtered product and customer selection.

 
Mode Price = VAR myTable = SUMMARIZE('Sales Fact','Sales Fact'[Price Per Unit],"Count",COUNT('Sales Fact'[Price Per Unit]))
VAR myTable2 = FILTER(myTable,[Count]=MAXX(myTable,[Count]))
VAR Mode1 = MAXX(LASTNONBLANK(myTable2,[Price Per Unit]),[Price Per Unit])
RETURN Mode1
 
Average Units Sold Mode Price  = CALCULATE(AVERAGE('Sales Fact'[UNIT_SALES]), FILTER('Sales Fact','Sales Fact'[Price Per Unit]=[Mode Price]))
 
 When I do this, it just calculates the average units. How do I pass the actual value of the mode to this filter?
 
Sales Fact
 
CUSTOMER_IDPRODUCT_IDDATEUNIT_SALESPrice Per Unit 
7157010361/7/201814.99
7157010361/14/201844.99
7157010361/21/201834.99
7157010361/28/201874.56
7157010362/4/201844.99
7157010362/11/201844.99
7157010362/18/201824.99
7157010362/25/201834.99
7157010363/4/201864.99
7157010363/11/201824.99
7157010363/18/201853.00
 
 
In this example, the mode correctly returns 4.99
But the Average Units Sold Mode Price measure just returns the average of 3.72
The correct answer should be 3.22
 
I should also mention in my Report, I have two slicers for Customer_ID = 71570 and Product_ID = 1036.
 
 

3 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you so much Ashish_Mathur !! This worked! I also wanted to create a measure for the Average Unit Sales when the price is not the mode. Would you be able to help with that?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        You are welcome.  If my previous reply helped, please mark it as Answer.  Try this measure

         

        Average units sold at non mode Price = AVERAGEX(FILTER(SUMMARIZE(VALUES(Data[Price Per Unit ]),Data[Price Per Unit ],"ABCD",COUNTROWS(Data),"EFGH",MIN(Data[Price Per Unit ]),"IJKL",AVERAGE(Data[UNIT_SALES])),[ABCD]<>MAXX(SUMMARIZE(VALUES(Data[Price Per Unit ]),Data[Price Per Unit ],"PQRS",COUNTROWS(Data)),[PQRS])),[IJKL])

        Hope this helps.