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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
AndreaLorenzo
Frequent Visitor

Calculate not working when using same field in table and formula filter

Hello everybody,

 

I'm trying to do something very simple, but I can't make it work:  from a Sales table, I need to compare the revenue for every product category related to another one.

 

I've  created two colums:

    Total Sales= SUM(PBI_Sales[Revenue))

     H Revenue= CALCULATE([Total Sales]; PBI_Products[Category]="H")

 

I'm getting this table:

 Captura1.JPG

 

However, if I dont use Product Category in the table, it works and filters by sales of that product:

 

Captura2.JPG

 

Is there something I'm missing? I've checked my table relantionships as well, and there's 1-N from Products to Sales, nothing weird.

 

Any help will be appreciated!


Kind regars

5 REPLIES 5
m3tr01d
Continued Contributor
Continued Contributor

@AndreaLorenzo From what table is coming the column "Prod Cat" on your table. Is it from the Product table?

Greg_Deckler
Super User
Super User

@AndreaLorenzo You are running into yet another reason I don't use CALCULATE. Basically, if you use CALCULATE with a straight filter clause (no FILTER function) then if the column you specify is already in the filter context, it replaces the filter context for that column. Otherwise, it adds to the filter context. 

CALCULATE function (DAX) - DAX | Microsoft Docs

 

It's hard to tell because I don't know your source data but it is probably something along those lines. As a general rule, if a function needs 50 blog articles to explain how it works, I tend to avoid it.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the feedback, @Greg_Deckler . Calculate is a bit difficult to understand, yes.

 

I finally got it working, maybe is not the most elegant solution, but it will do... 

 

H_Sales= var _tbl = ALLSELECTED(PBI_Sales)

var _catFiler= "H"

RETURN SUMX(FILTER(_tbl;  PBI_Sales[CategoryID]=_catFilter); [Revenue])
Thanks!

@AndreaLorenzo That's pretty much exactly how I would have done it.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
AndreaLorenzo
Frequent Visitor

Sorry, I forgot to say that my problem is that I don't know why the "H revenue" value is not showing for every row, only for the matching criteria product...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.