Forum Discussion
DAX Synex EARLIER Error
Hi,
My code keeps showing EARLIER/EARLIEST refers to an earlier row context which doesn't exist..
Any help would appreciate. Thanks.
12 Replies
- rohit1991Super User
Hi Amos_Lim ,
The error with EARLIER in your DAX formula occurs because EARLIER needs a valid outer row context to reference, but there’s none in your calculation.
SolutionYou can rewrite your formula to avoid EARLIER entirely. Use variables or ADDCOLUMN to create row contexts explicitly.
Updated Formula for a Calculated Column
If this is a calculated column:
Rank = RANKX( FILTER( 'ForkLiftData', 'ForkLiftData'[SAP Number] = EARLIER('ForkLiftData'[SAP Number]) ), 'ForkLiftData'[ForkLift Name], , ASC )This should work if the column is being calculated row by row. If it doesn’t, consider the alternatives below.
Alternative 1: Using VAR and ALL
To avoid EARLIER, explicitly define the context using VAR and ALL:
Rank = VAR CurrentSAPNumber = 'ForkLiftData'[SAP Number] RETURN RANKX( FILTER( ALL('ForkLiftData'), 'ForkLiftData'[SAP Number] = CurrentSAPNumber ), 'ForkLiftData'[ForkLift Name], , ASC )Alternative 2: Using GROUPBY (for aggregated contexts)
If you're ranking based on groups (e.g., SAP Number groups), use GROUPBY to create a new table first:
Rank = RANKX( GROUPBY( 'ForkLiftData', 'ForkLiftData'[SAP Number], "ForkLiftName", MAX('ForkLiftData'[ForkLift Name]) ), [ForkLiftName], , ASC )When to Use These Solutions
- Use Alternative 1 if you’re creating a calculated column or need a simple row-wise ranking.
- Use Alternative 2 if you're working with aggregated groups or want more explicit control over the grouping.
- bhanu_gautamSuper User
Amos_Lim Try using this
Rank =
VAR CurrentSAPNumber = 'ForkLiftData'[SAP Number]
RETURN
RANKX(
FILTER('ForkLiftData', 'ForkLiftData'[SAP Number] = CurrentSAPNumber),
'ForkLiftData'[ForkLift Name],
,
ASC
) - Ritaf1983Super User
Hi Amos_Lim
Please share sample data (excluding sensitive information) in text format, along with your expected result and any relevant logic. For guidance, refer to
How to provide sample data in the Power BI Forum
If possible, upload a simplified .pbix file using this guide:
- Amos_LimResolver I
I have taken a screenshot of the error and would like to resolve the issue as follows:
If a user (highlighted with a red arrow) appears for both Nichiyu and TCM forklifts, their information should only be displayed once. In the second row, only "TCM" should be shown instead of repeating the user's details. This approach will make the table easier to read, especially since it is a lengthy list.
- grazitti_sapnaSuper User
Hi Amos_Lim,
Please try using this DAX measure.
Rank =
RANKX(
FILTER(
'ForkLiftData',
'ForkLiftData'[SAP Number] = SELECTEDVALUE('ForkLiftData'[SAP Number])
),
'ForkLiftData'[ForkLift Name],
,
ASC
)🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
🔗 Curious to explore more? [Discover here].
Let’s keep building smarter solutions together!- Amos_LimResolver I
It gives and error message
A single value for column 'ForkLift Name' in table 'ForkLiftData' cannot be determined. this can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count or sum to get a single result- grazitti_sapnaSuper User
Could you please share sample data, along with your expected result and any relevant logic.
If possible, upload a simplified .pbix file using this guide:
- Bibiano_GeraldoSuper User
Hi Amos_Lim ,
Whats is the criteria for rank? what will determine to forklift stand in first position or last? please give more details to help you
- Amos_LimResolver I
I am trying to use DAX to rank the forklifts for each user.
and use DAX to display user details only for the first row of each user. Repeat the same DAX for other column except ForkLift Name
In summary:-
My intension was to make the table in the PBI dashboard that listed all users and the forklifts they are authorized to drive.
and currently, the table displays multiple rows of the same user, with their 'User Name', 'SAP Number', 'Forklift Name', 'POC', 'Department', and 'License Valid Until' if the user has access to different forklifts.
So for repeated user, I would like to just display their information in the 1st row, and for the 2nd or 3rd or more with the same user will just shows the different ForkLift and the rest of the columns show "Blank"?