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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
michaelshparber
Advocate V
Advocate V

Running Total with FILTER on a Fact Table not working

Hello friends,

***Edited***********

I think I've solved it.

This calculation is WRONG:

Running Sales Apples = CALCULATE([Running Sales],FILTER(Sales,Sales[Product]="Apples"))

And this one is right:

Running Sales Apples = CALCULATE([Running Sales],Sales[Product]="Apples")

So without FILTER() it is working.

Can anyone explain it, please?

********************

I have a simple Sales Fact Table and a Calendar table.

I have a Running Sales Amt which is working fine.

Running Sales = CALCULATE(Sales[Sales],FILTER(ALL('Calendar'),'Calendar'[Date]<=MAX('Calendar'[Date])))
When I add a Running Total measure that is filtered on a certain Product from the Fact table, like this:
Running Sales Apples = CALCULATE([Running Sales],filter(Sales,Sales[Product]="Apples"))
then I get wrong results - it doesn't sum up all the months...
Running.JPG
In my real-world scenario I cannot create a "Product" dimension so I need to filter the fact table.
 
How do I do it?
Thanks!
 
Here is a sample file:
 
9 REPLIES 9
v-yuta-msft
Community Support
Community Support

@michaelshparber ,

 

They are different on dax engine. The similar thread in stackoverflow below and two blogs may help you understand the difference:

https://stackoverflow.com/questions/50506030/dax-calculate-function-with-and-without-filter

 

Blogs:

https://www.red-gate.com/simple-talk/sql/bi/using-the-filter-function-in-dax/

https://exceleratorbi.com.au/the-filter-function-in-dax/

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yuta-msft 

Thanks, I've looked at all of the articles.

Nowhere could I find the answer - why doesn't my Running Total work?

I did include ALL(Calendar) - and it is working until I do FILTER(Sales,...)

Please help to understand

Thank you

michaelshparber
Advocate V
Advocate V

I think I solved it.

This calculation is WRONG:

Running Sales Apples = CALCULATE([Running Sales],FILTER(Sales,Sales[Product]="Apples"))

And this one is right:

Running Sales Apples = CALCULATE([Running Sales],Sales[Product]="Apples")

So without FILTER() it is working.

Can anyone explain it, please?

FrankAT
Community Champion
Community Champion

Hi @michaelshparber ,

see figure:

 

09-04-_2020_22-27-37.png

 

Regards FrankAT

Thanks @FrankAT 

I am looking for a solution to calculate for a specific product, such as Apples

 

Hi @michaelshparber ,

it's all insight:

 

09-04-_2020_23-19-17.png

Regards FrankAT

Sorry, @FrankAT 

ALLEXCEPT doesn't fit because there are other fields in Fact table that can be drillable.

The solution is on the surface, why the plain FILTER is not working?

 

Greg_Deckler
Super User
Super User

Hmm, well, see attached and let me know what you think:

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler thanks, but SUMX is not the solution I am looking for.

Because of ALL(Sales) - I cannot drill down to details....

When there are other fields in the Sales table - your measure will return same amount for all of them.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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