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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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