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

View all the Fabric Data Days sessions on demand. View schedule

Reply
cris1196
Helper I
Helper I

In Power Query, get a value by group with condition

Hi All!

 

I have the following table:

 

Date Order Store Filter
2022-05-01 25 5 False
2022-05-01 25 5 True
2022-06-01 38 7 True
2022-06-01 38 7 True
2022-07-01 82 5 False
2022-07-01 82 5 False

 

 

So, I want to group the values ​​by "Order", where if an order has at least one True, it returns True.

That is, the table should look like this:

 

Date Order Store Filter
2022-05-01 25 5 True
2022-06-01 38 7 True
2022-07-01 82 5 False

 

I know how to do it in Dax, but for certain reasons I need to do it in Power Query and I'm not getting it done. Any help is welcome. Thank you.

1 ACCEPTED SOLUTION
Ahmedy
Frequent Visitor

see attached
https://1drv.ms/u/s!AiUZ0Ws7G26RhgeuBRTrN49taB-R?e=RW7ym9

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUMzDVMzIwMlLSUTIyBRIg7JaYU5yqFKuDSz6kqBQhbQaTNrYAEuYkSpvDpC2MsFqOUz4WAA==", 
    BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Order = _t, Store = _t, Filter = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Order", Int64.Type}, {"Store", Int64.Type}, {"Filter", type logical}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", 
            each if Table.RowCount(Table.Distinct(_))>1 
            then Table.SelectRows(_,(x)=> x[Filter]=true) 
            else Table.Distinct(_)}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Order", "Store", "Filter"}, {"Order", "Store", "Filter"})
in
    #"Expanded Count"

View solution in original post

1 REPLY 1
Ahmedy
Frequent Visitor

see attached
https://1drv.ms/u/s!AiUZ0Ws7G26RhgeuBRTrN49taB-R?e=RW7ym9

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUMzDVMzIwMlLSUTIyBRIg7JaYU5yqFKuDSz6kqBQhbQaTNrYAEuYkSpvDpC2MsFqOUz4WAA==", 
    BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Order = _t, Store = _t, Filter = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Order", Int64.Type}, {"Store", Int64.Type}, {"Filter", type logical}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", 
            each if Table.RowCount(Table.Distinct(_))>1 
            then Table.SelectRows(_,(x)=> x[Filter]=true) 
            else Table.Distinct(_)}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Order", "Store", "Filter"}, {"Order", "Store", "Filter"})
in
    #"Expanded Count"

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors