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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
IAM
Helper III
Helper III

Group by - One is equal but other column is different

Hi!

 

I want to use a countifs function in Power Query, so I know I need to use group by, but how do I get the following:

 

Workorders -> need to be the same

Department -> need to be different 

 

Te goal is to regonize the rows that have the same workorder, but multiple departments working on it.

 

If anyone has a better way of achieving this, I am happy to hear it!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @IAM ,

 

If you want this:

Eyelyn9_1-1657596394063.png

Please try:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWBsJzgLGc4yxGNZYTCckITM4awYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Workorders = _t, Department = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Workorders", Int64.Type}, {"Department", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Workorders"}, {{"Distinct Depart each WorkOrder", each Table.RowCount(Table.Distinct(_)), Int64.Type}, {"All", each _, type table [Workorders=nullable number, Department=nullable text]}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Department"}, {"Department"}),
    #"Grouped Rows1" = Table.Group(#"Expanded All", {"Workorders", "Department"}, {{"each Work and Depart ", each Table.RowCount(_), Int64.Type}, {"All", each _, type table [Workorders=nullable number, Distinct Depart each WorkOrder=number, Department=nullable text]}}),
    #"Expanded All1" = Table.ExpandTableColumn(#"Grouped Rows1", "All", {"Distinct Depart each WorkOrder"}, {"Distinct Depart each WorkOrder"})
in
    #"Expanded All1"

 

 

And according to this:

The goal is to regonize the rows that have the same workorder, but multiple departments working on it.

 

If you want to sort tables by multiple columns, please use Table.Sort() and then add an Index column:

Eyelyn9_2-1657596560104.png

 

 

 

Best Regards,
Eyelyn Qin
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

4 REPLIES 4
Anonymous
Not applicable

Hi @IAM ,

 

If you want this:

Eyelyn9_1-1657596394063.png

Please try:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWBsJzgLGc4yxGNZYTCckITM4awYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Workorders = _t, Department = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Workorders", Int64.Type}, {"Department", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Workorders"}, {{"Distinct Depart each WorkOrder", each Table.RowCount(Table.Distinct(_)), Int64.Type}, {"All", each _, type table [Workorders=nullable number, Department=nullable text]}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Department"}, {"Department"}),
    #"Grouped Rows1" = Table.Group(#"Expanded All", {"Workorders", "Department"}, {{"each Work and Depart ", each Table.RowCount(_), Int64.Type}, {"All", each _, type table [Workorders=nullable number, Distinct Depart each WorkOrder=number, Department=nullable text]}}),
    #"Expanded All1" = Table.ExpandTableColumn(#"Grouped Rows1", "All", {"Distinct Depart each WorkOrder"}, {"Distinct Depart each WorkOrder"})
in
    #"Expanded All1"

 

 

And according to this:

The goal is to regonize the rows that have the same workorder, but multiple departments working on it.

 

If you want to sort tables by multiple columns, please use Table.Sort() and then add an Index column:

Eyelyn9_2-1657596560104.png

 

 

 

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

Vijay_A_Verma
Super User
Super User

Select Workorders followed by Department and then GroupBy. See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWBsJzgLGxiCJYzmGUEV4eLBdQRCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Workorders = _t, Department = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Workorders", "Department"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

Thanks for your reply, this counts the rows where workorders and departments are the same, I need the count f

when workorder = the same, but department is NOT the same.

For below table, can you show what output is expected or if you have any sample table which you can post and also post the result.

WorkordersDepartment
1A
1B
1A
1B
1B
1C
2A
2A
2A
2B

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.