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
NNaj
Helper IV
Helper IV

Power query create new column X where: IF any value in column A is true, return true for all X

Hi Everyone,

 

If any.PNG

 

Column1 is the company name. Each company has many products (not shown). Each product has a rating. I want to create a new column that looks at each company and returns fail, watchlist, or pass based on the ratings on the products.

 

If any product fails, return fail for every row in this new column

 

If any product is a watch list, return fail.

 

If any product is green (with no fails or watchlists) return pass for all rows for that company

 

I need to do this on power query because I need to use this column in a left outer join with another table. Thank you in advance for all your help.

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @NNaj 

 

Let me know if you'd like to get below results:

Add below measures:

Fail = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="Fail"))
No rating = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="No Rating"))
Pass = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="Pass"))
Watch list = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="Watch list"))

 Final measure:

Measure = SWITCH(TRUE(),[Fail]="Fail","Fail",[Watch list]="Watch list","Fail",[Pass]="Pass","Pass",[No rating]="No Rating","No Rating")

004.PNG

Pbix attached.

Community Support Team _ Dina Ye
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

5 REPLIES 5
AnkitBI
Solution Sage
Solution Sage

Hi @NNaj - If you can provide sample data, then I will be able to help.

 

 

sample data.PNG

 

Attached is some sample data, cant seem to be able to atach an excel sheet.

The new column is what I need to create on power query

Hi @NNaj 

 

Let me know if you'd like to get below results:

Add below measures:

Fail = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="Fail"))
No rating = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="No Rating"))
Pass = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="Pass"))
Watch list = CALCULATE(MAX('Table (3)'[Rating]),FILTER(ALLEXCEPT('Table (3)','Table (3)'[Company]),[Rating]="Watch list"))

 Final measure:

Measure = SWITCH(TRUE(),[Fail]="Fail","Fail",[Watch list]="Watch list","Fail",[Pass]="Pass","Pass",[No rating]="No Rating","No Rating")

004.PNG

Pbix attached.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

Thank you for this. I was wondering if there is a way to do this in Power Query in the edit queries page. I need to do it like this because I need to merge this table with another using a left outer join and at the moment when I try to create the join The measure is not visible in the table

#

Hi @NNaj  Check below solution for PQ

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcg1R0lEyBGK3xMwcpVgdqIgREAckFhcjRIyB2C9fISixJDMvHSFsgiHs6AQUMkXWDxYxw67QHLuwBYawkyNQyBKIwxNLkjMUcjKLSxDihgbY1Rsa4hA3whB3dwGJY/oSIo7pTYi4Kap4LAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Company = _t, Product = _t, Rating = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"Product", Int64.Type}, {"Rating", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Company"}, {{"AllRows", each _, type table [Company=text, Product=number, Rating=text]}}),
    Custom1 = Table.AddColumn(#"Grouped Rows","FailPass",each if List.ContainsAny([AllRows][Rating],{
"Fail","Watch list"}) then "Fail" else if List.Contains([AllRows][Rating],"Pass") then "Pass" else "No Rating"),
    #"Expanded AllRows" = Table.ExpandTableColumn(Custom1, "AllRows", {"Product", "Rating"}, {"Product", "Rating"})
in
    #"Expanded AllRows"

 

Thanks
Ankit Jain
Do Mark it as solution if the response resolved your problem. Do Kudo the response if it seems good and helpful.

 

 

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.