Forum Discussion

SJRJEJ's avatar
SJRJEJ
New Member
3 years ago
Solved

Reference current row value in Filter expression

Hi , 
I seem to be struggling with a  problem in PowerBI.
 I will try to explain the issue with the Product and Sales table example .
In my report , I have a drop down filter for Product and I have a Sales table from which I want to display the sales for the Product and also the total sales for the Product Category under which the Item belongs 
 PRODUCT TABLE
ProductCategory Item
BookB1
BookB2
ClothingDress
FurnitureTable
BookB3
ClothingShirt
FurnitureChairs

 

 

SALES TABLE

Item     Sales    ProdCat

B1100Book
Dress20Clothing
B2200Book
Table10Furniture
Shirt30Clothing
B320Book
Chairs60Furniture
 
 
 

 When I hardcode a particular Product Category , the DAX works :

ProductSales = CALCULATE(sum(Sales[Sales]),FILTER(ALL(Sales), Sales[ProdCat] = "Book"))
In the Above DAX , I want to dynamically reference the Product Category of the item selected in the drop down list box .
I tried using EARLIER function to reference the current value of Sales[ProdCat] but I got the below error .

 

 

How do I override the Filter Context and also apply filter based on the current value of the row?

Any advice would be greatly appreciated.

  • =VAR _prdcat=VALUES(Product[ProductCategory]) RETURN CALCULATE(SUM(Sales[Sales]),FILTER(ALL(Product,Product[ProductCategory] IN _prdcat))

2 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    =VAR _prdcat=VALUES(Product[ProductCategory]) RETURN CALCULATE(SUM(Sales[Sales]),FILTER(ALL(Product,Product[ProductCategory] IN _prdcat))

    • SJRJEJ's avatar
      SJRJEJ
      New Member

      Thank you so very much !!!! That worked .

      Very grateful for your help .