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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Goodkat
Helper I
Helper I

Text.Combine within Table.Group fails on numeric keys, even with Number.ToText

Dear Power Query enthusiasts,

I am regularly thrilled by the efficiencies and smart dataflows PowerQuery enables. To further aggregate which data is worth to display, and which could be hidden, I had a look at the group by functionality.

https://c.gmx.net/@324888734501700174/7lpIroMCTFSyvoig62x16A

I am grouping two numeric dimensions and a dimension containing numeric Step IDs:

 

DataType_PIDText = Table.TransformColumnTypes(Add_BaseID,{{"Step ID", type text}}),

    Group = Table.Group(DataType_PIDText, {"Base ID"}, {{"2021 Actual", each List.Sum([2021 Actual]), type number}, {"2021 Plan", each List.Sum([2021 Plan]), type number}, {"Step ID", each Text.Combine([Step ID], "#(lf)")}})

 

That works, but as a prerequisite of the Text.Combine function the [Step ID] must be converted into text before. But as this is one of my major mapping keys and is by nature an integer, artificially convert into text for this one step (and subsequently convert it back) does not appear appropriate.

So I tried in the second query of the linked file (Aggregation_condensed) to bring in Number.ToText:

 

Group = Table.Group(Add_BaseID, {"Base ID"}, {{"2021 Actual", each List.Sum([2021 Actual]), type number}, {"2021 Plan", each List.Sum([2021 Plan]), type number}, {"Step ID", each Text.Combine(Number.ToText([Step ID]), "#(lf)")}})

 

But I get errors thrown. I was searching the internet with various key word combinations, but I did not find anything. Combining Text there are multiple posts, but numeric keys into a text field I failed to find.

I would be helpful if someone from the forum could direct me, whether this is possible at all and what I am doing wrong.

 

Thank you very much in advance!

Best regards, Andreas

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

There are few ways you can solve ...

 

sevenhills_0-1695853558353.png

Assuming Sub Step ID - copy is the duplicated column and marked as text.

 

Method 1: Copy the number column and change the type as text and then use Text.Combine; Check "a" column

 

Method 2: Using Text.Combine, List.Transform. Check "b" column

 

Method 3: we may need distinct some times, using method 2, I can make distinct. Check "c" column.

 

 

 

= Table.Group(#"Changed Type", {"Step ID"}, {{"sum1", each List.Sum([2021 Actual]), type nullable number}, {"sum2", each List.Sum([2021 Plan]), type nullable number}
     , {"a", each Text.Combine([#"Sub Step ID - Copy"], ","), type text}
     , {"b", each Text.Combine(List.Transform([Sub Step ID], Text.From), ", "), type text}
     , {"c", each Text.Combine(List.Transform(List.Distinct([Sub Step ID]), Text.From), ", "), type text}})

 

 

 

sevenhills_1-1695853672742.png

 

 

Hope it helps, Thanks

View solution in original post

3 REPLIES 3
sevenhills
Super User
Super User

There are few ways you can solve ...

 

sevenhills_0-1695853558353.png

Assuming Sub Step ID - copy is the duplicated column and marked as text.

 

Method 1: Copy the number column and change the type as text and then use Text.Combine; Check "a" column

 

Method 2: Using Text.Combine, List.Transform. Check "b" column

 

Method 3: we may need distinct some times, using method 2, I can make distinct. Check "c" column.

 

 

 

= Table.Group(#"Changed Type", {"Step ID"}, {{"sum1", each List.Sum([2021 Actual]), type nullable number}, {"sum2", each List.Sum([2021 Plan]), type nullable number}
     , {"a", each Text.Combine([#"Sub Step ID - Copy"], ","), type text}
     , {"b", each Text.Combine(List.Transform([Sub Step ID], Text.From), ", "), type text}
     , {"c", each Text.Combine(List.Transform(List.Distinct([Sub Step ID]), Text.From), ", "), type text}})

 

 

 

sevenhills_1-1695853672742.png

 

 

Hope it helps, Thanks

Dear sevenhills,

 

Please accept my apologies for the late delay. Here in Germany was a longer holiday and I was visiting my family, not in reach of a computer and appropriate time. But now I am back and see gratefully your reply with three alternative options. Very cool! And all of them do work! Your idea of combining List.Distinct into option c is very clever. It will save me another interim step!

 

I will mark your reply as 'accept a solution' and transfer the logic of your option c into my datamodel.

 

Thank you once again for your time and help that gives me a path forward, but more important, provides a learning!

 

Best regards, Goodkat

Dear Goodkat,

 

Thanks for your reply and we all understand that sometimes due to personal reasons, we may delay in replying to our own thrreads.

 

Glad to hear that you get to visit your family and enjoyed the holidays.

 

Hope you got the problem resolved related to this post. 

 

Best Regards, SevenHills

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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