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

label group of rows based on first row value

Hi all,


I am trying to label a group of rows based on the value of a column for the first row.

This is an order data table, that looks like this :

 

Order NumberPhaseReview Mode
123ABC1Manual review
123ABC2Automated review
123ABC3Automated review
123ABC4Automated review
456DEF1Automated review
456DEF2Automated review
456DEF3Manual review
456DEF4Manual review

 

So what I would like to do is label each Order Number, in a new calculated column, based on the review mode during phase 1 e.g.:

123ABC --> "Manual review"

456DEF --> "Automated Review"

 

From what I've seen, many people have similar issues but with numeric or date values and they tend to use CALCULATE and MAX/MIN for example.
In that case, I work with string values and I have several column like that that I'd like to evaluate, so I'd try to avoid replacing strings by numerical equivalents (i.e. "automated" = 0, "manual" = 1).

Would you have any suggestion/hint as how to deal with this ?


Thanks in advance,

Regards,

Pierre

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @highxsky 

 

Based on your description, you may create a calculated column or a measure as below.

 

Calculated column:
Result Column = 
var _ordernumber = 'Table'[Order Number]
return
CALCULATE(
    MAX('Table'[Review Mode]),
    FILTER(
        ALL('Table'),
        'Table'[Order Number] = _ordernumber&&
        'Table'[Phase] = 
        CALCULATE(
            MIN('Table'[Phase]),
            FILTER(
                ALL('Table'),
               'Table'[Order Number] = _ordernumber
            )
        )
        
    )
)

Measure:
Result Measure = 
var _ordernumber = SELECTEDVALUE('Table'[Order Number])
return
CALCULATE(
    MAX('Table'[Review Mode]),
    FILTER(
        ALL('Table'),
        'Table'[Order Number] = _ordernumber&&
        'Table'[Phase] = 
        CALCULATE(
            MIN('Table'[Phase]),
            FILTER(
                ALL('Table'),
               'Table'[Order Number] = _ordernumber
            )
        )
        
    )
)

 

 

Result:

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @highxsky 

 

Based on your description, you may create a calculated column or a measure as below.

 

Calculated column:
Result Column = 
var _ordernumber = 'Table'[Order Number]
return
CALCULATE(
    MAX('Table'[Review Mode]),
    FILTER(
        ALL('Table'),
        'Table'[Order Number] = _ordernumber&&
        'Table'[Phase] = 
        CALCULATE(
            MIN('Table'[Phase]),
            FILTER(
                ALL('Table'),
               'Table'[Order Number] = _ordernumber
            )
        )
        
    )
)

Measure:
Result Measure = 
var _ordernumber = SELECTEDVALUE('Table'[Order Number])
return
CALCULATE(
    MAX('Table'[Review Mode]),
    FILTER(
        ALL('Table'),
        'Table'[Order Number] = _ordernumber&&
        'Table'[Phase] = 
        CALCULATE(
            MIN('Table'[Phase]),
            FILTER(
                ALL('Table'),
               'Table'[Order Number] = _ordernumber
            )
        )
        
    )
)

 

 

Result:

b2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,


thanks for the reply and the link.

 

In my case, I am trying to retrieve the value from the first row of item A and apply it to each row row of item A.

I have tried some manipulations with your model, but without getting the desired output.

 

First part of the query - with a slight FILTER twist - works well, I get the output I'm looking for.
Second part of the query is another story though.

 

Part 1, DaX studio, output OK

Query part 1.PNG


Part 2, Power Query, output KO

Query part 2.PNG


Could you please provide me further hints so I can solve that issue?

Thanks again,

Pierre

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.