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
Anonymous
Not applicable

Groupby with a Condition

Wow. I didn't think this would be so involved. In Power Query Editor how can I convert the table below grouping Store Managers into two categories, if they failed an audit bucket as "Failed at least 1 Audit", if they have never failed, bucket them as "Passed all Audits":

Starting Table

Store ManagerAudit Violation
233Failed Audit
233Passed Audit
233Passed Audit
238Passed Audit
238Passed Audit
240Failed Audit
249Passed Audit
249Passed Audit
249Passed Audit

 

Resulting End Table:

Store ManagerAudit Failed or Passed
233Failed at least 1 Audit
238Passed all Audits
240Failed at Least 1 Audit
249Passed all Audits

 

Help is much appreciated here. I couldn't believe this was so difficult.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2VtJRckvMzElNUXAsTcksUYrVgQkHJBYXEydsQYqwiQFWK00ssasmWjgWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store Manager" = _t, #"Audit Violation" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Store Manager"}, {{"Result", each let l = [Audit Violation], res = List.Accumulate(l, false, (s,c) => s or Text.Contains(c, "Failed", Comparer.OrdinalIgnoreCase)) in if res then "Failed at least once" else "Passed"}})
in
    #"Grouped Rows"

 

 

Screenshot 2021-06-27 123704.png

 

Screenshot 2021-06-27 124759.png

 

For fun only,

Untitled.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2VtJRckvMzElNUXAsTcksUYrVgQkHJBYXEydsQYqwiQFWK00ssasmWjgWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store Manager" = _t, #"Audit Violation" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Store Manager"}, {{"Result", each let l = [Audit Violation], res = List.Accumulate(l, false, (s,c) => s or Text.Contains(c, "Failed", Comparer.OrdinalIgnoreCase)) in if res then "Failed at least once" else "Passed"}})
in
    #"Grouped Rows"

 

 

Screenshot 2021-06-27 123704.png

 

Screenshot 2021-06-27 124759.png

 

For fun only,

Untitled.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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.

Top Solution Authors