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
Abhisek
New Member

Earlier Function : How does it work

Dear POWER BI Experts ,

I have the below  Test Data :

 

CREATE TABLE Dax_Test_Product ( ProductID INT , UnitPrice INT )

 

INSERT INTO Dax_Test_Product VALUES ( 1 , 10)
INSERT INTO Dax_Test_Product VALUES ( 2 , 20)
INSERT INTO Dax_Test_Product VALUES ( 3 , 30)
INSERT INTO Dax_Test_Product VALUES ( 4 , 50)
INSERT INTO Dax_Test_Product VALUES ( 5 , 60)
INSERT INTO Dax_Test_Product VALUES ( 6 , 70)
INSERT INTO Dax_Test_Product VALUES ( 7 , 100)
INSERT INTO Dax_Test_Product VALUES ( 8 , 110)
INSERT INTO Dax_Test_Product VALUES ( 9 , 130)
INSERT INTO Dax_Test_Product VALUES ( 10 , 150)
INSERT INTO Dax_Test_Product VALUES ( 11 , 200)
INSERT INTO Dax_Test_Product VALUES ( 12 , 230)
INSERT INTO Dax_Test_Product VALUES ( 13 , 240)
INSERT INTO Dax_Test_Product VALUES ( 14 , 250)
INSERT INTO Dax_Test_Product VALUES ( 15 , 270)
INSERT INTO Dax_Test_Product VALUES ( 16 , 300)

 

The question - 
Now If we want to Rank the products we can use the below formula -
Column_Rank = COUNTROWS(Filter(Dax_Test_Product,Dax_Test_Product[UnitPrice]<Earlier(Dax_Test_Product[UnitPrice])) ) +1

 

Now here , since I am using this in the calculated colums it is creating a new row context and then the filter also creates one another new row context , Could you please let me know how the row context created by the Filter actually takes place here?

 

I would also like to know about the context switches , how it happens .

 

Thanks in advance ,

Abhisek

1 REPLY 1
v-yulgu-msft
Employee
Employee

Hi @Abhisek,

 

According to this MSDN document, we can know that Earlier() function returns the current value of the specified column in an outer evaluation pass of the mentioned column. And the Creating a Rank Value section in this article has described the method of calculation detailedly step by step.

 

As per my understanding, Earlier function works like cross join by itsefl. After cross join, the table expand to 16 x 16 rows, then, filter records based on a specific condition. In your table, there are 16 rows in the column, approximately a 16 x 16 operations will be required.

 

Besides, please refer to this article that will help you understand row context and earlier function more clearly.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.