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
Esott
Regular Visitor

How to return the first value of a second column based on a first column values

Hello everybody, 

 

Im new to Dax world so I kindly ask for your help.

 

 

i am stuck on this problem, where I would like to build a calculate column where, for every distinct value on a first column, i want to return  the first identifiable value on the second column and this value must be equal for every row of the calculated column till the value on the first change.

 

Here's an example:

 

Code ProductCalculate Column
1234chickenchicken
1234chicken chicken
1234chicken 2chicken
1235sandwich 1sandwich 1
1235sandwich sandwich 1
1235sandwichsandwich 1
1236soup soup 
1236soup soup 
1236soup 2soup 

 

As you can see, id like that for the code 1234 the calculated column will return the first value finded on the column product, which is "Chicken" (yes i'm hungry right now 🙂)

 

Anybody has any idea or suggestion?

 

Really appreciate your help and thank you in advance,

 

E

 

 

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

DAX has no concepts of column numbers or row numbers. Augment your sample data with an index column to allow DAX to understand the order of the rows.

 

CodeProductIndex

1234 chicken 1
1234 chicken 2
1234 chicken 2 3
1235 sandwich 1 4
1235 sandwich 5
1235 sandwich 6
1236 soup 7
1236 soup 8
1236 soup 2 9

 

Once the index is in place the DAX formula becomes trivial.

 

Column = 
var i = CALCULATE(min('Table'[Index]),ALLEXCEPT('Table','Table'[Code ]))
return CALCULATE(min('Table'[Product]),ALLEXCEPT('Table','Table'[Code ]),'Table'[Index]=i)

 

lbendlin_0-1646519162341.png

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

DAX has no concepts of column numbers or row numbers. Augment your sample data with an index column to allow DAX to understand the order of the rows.

 

CodeProductIndex

1234 chicken 1
1234 chicken 2
1234 chicken 2 3
1235 sandwich 1 4
1235 sandwich 5
1235 sandwich 6
1236 soup 7
1236 soup 8
1236 soup 2 9

 

Once the index is in place the DAX formula becomes trivial.

 

Column = 
var i = CALCULATE(min('Table'[Index]),ALLEXCEPT('Table','Table'[Code ]))
return CALCULATE(min('Table'[Product]),ALLEXCEPT('Table','Table'[Code ]),'Table'[Index]=i)

 

lbendlin_0-1646519162341.png

 

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.