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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
LéaGr
Helper I
Helper I

Create a column from loop

Hi everybody,

 

I have an issue creating a column from what I feel could come from a "for each" loop. As no function of the sort exists in DAX I am stuck.

 

Here is a simplified version of my data

 

ID           Status

554            1

555            1

555            3

556            2

 

The IDs are not unique so one ID can have several status (2 or more), I would like to create a column that find the maximum status value for each ID (ex : Identify that for ID 555 the max status is 3 and in the new column replace 1 by 3). That would give us :

 

ID           Status         Max status

554            1                     1 

555            1                     3

555            3                     3 

556            2                     2

 

Does somedy know how to achieve that?

 

Many thanks for your help!!

Best,

 

Léa

1 ACCEPTED SOLUTION
Pragati11
Super User
Super User

Hi @LéaGr ,

 

You can create a Calculated column as follows using DAX:

 

TestCol = CALCULATE(
                                    MAX(Table1[Status]),
                                    FILTER(
                                               ALLSELECTED(Table1), Table1[ID] = EARLIER(Table1[ID])
                                              )
                                    )
 
Replace Table1 in above DAX expression with your's table-name.
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

6 REPLIES 6
BIswajit_Das
Impactful Individual
Impactful Individual

it's working for numbers perfectly but what about incase of text

e.g

name           visitplace

x                  a

x                  b

x                  a

y                  b

Requied output:-

name           visitplace            MAX

x                  a                            a                      

x                  b                            a

x                  a                            a

y                  b                            b

Pragati11
Super User
Super User

Hi @LéaGr ,

 

You can create a Calculated column as follows using DAX:

 

TestCol = CALCULATE(
                                    MAX(Table1[Status]),
                                    FILTER(
                                               ALLSELECTED(Table1), Table1[ID] = EARLIER(Table1[ID])
                                              )
                                    )
 
Replace Table1 in above DAX expression with your's table-name.
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Thanks for your swift answer @Pragati11 !!

That works, I will mark it as the solution. I have a complementary question thow, will the column adapt to the filters? I have another column with dates and a date filter in my page, will the maximum be determined between the selected date or once and for all among all data?

It it does not adapt to the filter, do you know how I could acheive that?

 

Many thanks,

Best,

 

Léa

Hi @LéaGr ,

 

Yes this solution will work with filters as well. You can test it.

If it doen't work let me know.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi @Pragati11 ,

 

I tested recently the solution and I was indeed able to create the calculated column but it does not adapt to filter. Indeed I have a date filter and the maximum seems to be calculated among the whole table and not the filtered table by date.

Maybe an equivalent measure could do the job?

I can send you the pbix if it helps.

Thanks a lot!

 

Best,

 

Léa

Gear thank you very much! I really appreciate how helpful and fast you are.

 

Have a great day!

 

Léa

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.