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
Anonymous
Not applicable

Filter context, context transition while adding a column using dax

Hey Guys, i am new to power bi and need help in understanding a few basic concepts regarding filter context and context transition and the application orders in adding a new columns via DAX. Below are 4 dax formulas and i want to understand how they work, as i am not able to decode the output perfectly:

 

1) a1 = CALCULATE(

AVERAGE(Prices[close]),FILTER(ALL(Prices[Date]),AND(Prices[Date]>LOOKUPVALUE(Prices[Date],Prices[Stock],EARLIER(Prices[Stock]),Prices[Day Number],EARLIER(Prices[Day Number]) - 5 ),Prices[Date]<=EARLIER(Prices[Date]))))
 
2) a2 = CALCULATE(
AVERAGE(Prices[close]),FILTER(ALL(Prices[close]),AND(Prices[Date]>LOOKUPVALUE(Prices[Date],Prices[Stock],EARLIER(Prices[Stock]),Prices[Day Number],EARLIER(Prices[Day Number]) - 5 ),Prices[Date]<=EARLIER(Prices[Date]))))
 
3) a3 = CALCULATE(

AVERAGE(Prices[close]),FILTER(ALL(Prices[Date]),AND(Prices[Date]>=LOOKUPVALUE(Prices[Date],Prices[Stock],EARLIER(Prices[Stock]),Prices[Day Number],EARLIER(Prices[Day Number]) - 5 ),Prices[Date]<=EARLIER(Prices[Date]))),ALLEXCEPT(Prices,Prices[Stock]))

 

4) a4 = CALCULATE(

AVERAGE(Prices[close]),FILTER(ALL(Prices[close]),AND(Prices[Date]>=LOOKUPVALUE(Prices[Date],Prices[Stock],EARLIER(Prices[Stock]),Prices[Day Number],EARLIER(Prices[Day Number]) - 5 ),Prices[Date]<=EARLIER(Prices[Date]))),ALLEXCEPT(Prices,Prices[Stock]))

 

I basically just want to understand the theory behind all of these.

 

Thanks in advance

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

For a1,it means that you are getting an average value of "Prices[close]",which have filters of "FILTER(ALL(Prices[Date]),AND(Prices[Date]>LOOKUPVALUE(Prices[Date],Prices[Stock],EARLIER(Prices[Stock]),Prices[Day Number],EARLIER(Prices[Day Number]) - 5 ),Prices[Date]<=EARLIER(Prices[Date]))))"

For function earlier you can understand as the current row.

For "lookupvalue"is to get a related value from another column.

 

For references,pls see below:

Calculate: https://docs.microsoft.com/en-us/dax/calculate-function-dax

Filter: https://docs.microsoft.com/en-us/dax/filter-function-dax

Average: https://docs.microsoft.com/en-us/dax/average-function-dax

Earlier:  https://docs.microsoft.com/en-us/dax/earlier-function-dax

Lookupvalue:  https://docs.microsoft.com/en-us/dax/lookupvalue-function-dax

 

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

View solution in original post

1 REPLY 1
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

For a1,it means that you are getting an average value of "Prices[close]",which have filters of "FILTER(ALL(Prices[Date]),AND(Prices[Date]>LOOKUPVALUE(Prices[Date],Prices[Stock],EARLIER(Prices[Stock]),Prices[Day Number],EARLIER(Prices[Day Number]) - 5 ),Prices[Date]<=EARLIER(Prices[Date]))))"

For function earlier you can understand as the current row.

For "lookupvalue"is to get a related value from another column.

 

For references,pls see below:

Calculate: https://docs.microsoft.com/en-us/dax/calculate-function-dax

Filter: https://docs.microsoft.com/en-us/dax/filter-function-dax

Average: https://docs.microsoft.com/en-us/dax/average-function-dax

Earlier:  https://docs.microsoft.com/en-us/dax/earlier-function-dax

Lookupvalue:  https://docs.microsoft.com/en-us/dax/lookupvalue-function-dax

 

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

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.