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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Victor_AguirreV
Regular Visitor

Calculate with/without Filter() function and

Hey guys,

 

So apparently I have been missing something very crucial about how the calculate function works. I am currently on the Datacamp course to get certified, and the question is asking to create a  measure that sums a field, filtering it based on the date of another table.

 

My initial measure was:

 

Victor_AguirreV_0-1709007189150.png

 

But after trying and failing, the "hint" tells me that the correct formula is:

 

Victor_AguirreV_1-1709007219785.png

 

So I must be missing a good definition on how the calculate formula works. Why is it the correct version of the calculate without the Filter() function? It does give very different results, but I am not sure I understand why?

 

I was reading something that using it without, it moves from row to filter context... and while I thought I had that well understood... I am not seeing that I really don't. Help please?

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

It looks like you are trying to calculate a running total by date.  Here's the approach i would use:

  1. Create a Calendar Table and a relationship (Many to One and Single) from the Recorded Date column to the Date column of the Calendar Table
  2. To your visual, drag Date from the Calendar Table
  3. Write this measure

RT = calculate(sum(Expenditures[Budgeted amout]),datesytd(Calendar[Date],"31/12"))

The RT will resent on Jan 1 of each year.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

It looks like you are trying to calculate a running total by date.  Here's the approach i would use:

  1. Create a Calendar Table and a relationship (Many to One and Single) from the Recorded Date column to the Date column of the Calendar Table
  2. To your visual, drag Date from the Calendar Table
  3. Write this measure

RT = calculate(sum(Expenditures[Budgeted amout]),datesytd(Calendar[Date],"31/12"))

The RT will resent on Jan 1 of each year.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-shex-msft
Community Support
Community Support

Hi @Victor_AguirreV,

I'd like to suggest you take a look at the following blog about row and filter context if it help you to learning with Dax knowledges.

Row Context and Filter Context in DAX - SQLBI

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Daniel29195
Super User
Super User

@Victor_AguirreV 

when you use a filter predicate in calculate,   power bi transform it into this : 

filter (

all ( 'recorded date'[date] ) ,

'recorded date'[date] < = max(expenditures[recorded date])
)

 

so basically there is a difference between this , and the one you are writing, which is : 

filter( 'recorded date',  'recorded date' <= max ( expenditures(recorded date] ) ) 

 

and the difference is indicative, since in the first, you are removing any filter from the filter context then add the filter , however in the second one, you are adding a filter to the existing filter context. 

 

hope this helps .

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.