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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
mikecrobp
Helper I
Helper I

Power M Query: How to specify a condition in aggregate of Table.Group

I really like the fact that you get to choose your own aggregate functions in M

In particular Text.Combine so that I can aggregate by concatenating text. eg databases for Server1, count = 4, names = DB1/DB2/DB3/DB4

 

I have an example where I have multiple applications associated with a server, some live and some now decommisioned but I want to report:

1) How many applications in total

2) How many still Live

3) What the names of the Live ones are

 

I can get close with:

 

#"Grouped Rows" = Table.Group(#"Filtered out xxx", {"ServerName", "DecomStatus", "ServerStatusReason"}, {{"AppCount", each Table.RowCount(_), type number}, {"LiveAppCount", each List.Sum([LiveApp]), type number},  {"ApplicationNames", each Text.Combine([AppName], "/"), type text}}),

LiveAppname is blank if application is not live, but this gives me blanks for the "dead" applications as well and they don't look good in app1/app2///app5

 

I have tried to limit the span of the last "each" to only include live apps - but I can't fathom the syntax of each with a condition (is it possible). I have tried with/without braces. But fundamentally I don't get the syntax

 

#"Grouped Rows" = Table.Group(#"xxx", {"ServerName", "DecomStatus", "ServerStatusReason"}, { "ApplicationNames", each ([LiveAppName] <> "") Text.Combine([LiveAppName], "#(cr)#(lf)"), type text})
1 ACCEPTED SOLUTION

Hi @mikecrobp

 

You may try to use List.Select. Show a sample as below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUSpWitWBsFLArCQgKw3OgjNKlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"Count", each Text.Combine(List.Select([Column2], each _ <>"") ,"/"), type text}})
in
    #"Grouped Rows"

Regards,

Cherie

Community Support Team _ Cherie Chen
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
Thejeswar
Super User
Super User

Hi @mikecrobp,

I think the below DAX statement will help you achieve your need

 

#"Grouped Columns"= Table.Group(#"XXX",{"ServerName","DecmStatus","ServerStatusReason"},{{"ApplicationNames", each Text.Combine([LiveApp],"/")}})

When I tested with some dummy data, this did not show me the blank spaces

Sorry for the delay. In fact my issue is not with using text.Combine as an aggregate function.

it was to use a further qualifier as part of the "each"

I have solved this by creating 2 queries and then joining (merging) them.

 

Mike

Hi @mikecrobp

 

You may try to use List.Select. Show a sample as below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUSpWitWBsFLArCQgKw3OgjNKlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"Count", each Text.Combine(List.Select([Column2], each _ <>"") ,"/"), type text}})
in
    #"Grouped Rows"

Regards,

Cherie

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

Yes. That is what I am looking for. Thank you

v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @mikecrobp

 

Here is the reference for you. If it is not your case, please share some simplified data sample.

 

https://community.powerbi.com/t5/Desktop/Agroup-and-concatenate-column-with-a-common-value/td-p/2118...

 

Regards,

Cherie

 

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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