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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
Microsoft Employee
Microsoft 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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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