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
msheppard602
Frequent Visitor

syntax help to extract values in desc order

Hi, 

I am not an expert using this syntax and hoping I can tap the brain trust here to accomplish what I want quicker than tinkering with list.sort syntax on my own.  Haven't been able to accomplish with sorting in previous pbi steps.

 

Using power bi, created a table and have grouped it to specifically extract a space separated list of (if your in healthcare) CPT codes.  

 

It's specifically the order I'm looking to impact here.  I've used the following logic to produce field called CPT_pattern and it produces what I want.. as far as the pattern.  For example patterns returned are 

 

90833 99214

90833 99213

 

However I want the field to list the 99214 or 99213 first:  99214 90833. 

 

How do I override the default asc to accomplish what I need?  

 

After a group by I added a custom field= Table.AddColumn(#"Grouped Rows", "CPT_pattern", each Table.Column([Data],"CPT"))

 

This is the step where I extract the values = Table.TransformColumns(#"Added Custom", {"CPT_pattern", each Text.Combine(List.Transform(_, Text.From), " "), type text})

1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

Try this:

 

Table.TransformColumns(#"Added Custom", {"CPT_pattern", each Text.Combine(List.Transform(List.Sort(_, Order.Descending), Text.From), " "), type text})

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

2 REPLIES 2
watkinnc
Super User
Super User

Try this:

 

Table.TransformColumns(#"Added Custom", {"CPT_pattern", each Text.Combine(List.Transform(List.Sort(_, Order.Descending), Text.From), " "), type text})

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Brilliant!  I started reading about table.buffer and was hoping there was an easier solution.  You provided it.  Thank you.  

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors