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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
AllisonB
Frequent Visitor

Add an index/order column

I have created a table that I'm using to group data but I need to be able to order it correctly in visulizations and so want to add an index/order column but I can't work out where or how to add another column into the formula used to create the table. 

What I want is a column with 1 - 24 following the order they can been seen in in the table below

AllisonB_0-1739977936027.png

 

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @AllisonB 

 

Please try this:

Unique Callers Band Table = 
VAR _Table1 = SUMMARIZE(ADDCOLUMNS(GENERATESERIES(1,20,1),"Times Called",FORMAT([Value],"")),[Times Called])
VAR _Table2 = {"21-50"}
VAR _Table3 = {"51-100"}
VAR _Table4 = {"101-200"}
VAR _Table5 = {"201+"}
VAR _UnionTable = ADDCOLUMNS(UNION(_Table1,_Table2,_Table3,_Table4,_Table5),"_NUM",
    VAR _String = IF(CONTAINSSTRING([Times Called],"-"),"-","+")
    VAR _Num = SEARCH(_String,[Times Called],1,BLANK())
    RETURN
    VALUE(IFERROR(MID([Times Called],1,_Num-1),[Times Called])))
RETURN 
SELECTCOLUMNS(_UnionTable,[Times Called],"Sort1",RANKX(_UnionTable,[_NUM],,ASC))

The result is as follow:

vzhengdxumsft_0-1740036439875.png

 

 

Best Regards

Zhengdong Xu
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

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @AllisonB 

 

Please try this:

Unique Callers Band Table = 
VAR _Table1 = SUMMARIZE(ADDCOLUMNS(GENERATESERIES(1,20,1),"Times Called",FORMAT([Value],"")),[Times Called])
VAR _Table2 = {"21-50"}
VAR _Table3 = {"51-100"}
VAR _Table4 = {"101-200"}
VAR _Table5 = {"201+"}
VAR _UnionTable = ADDCOLUMNS(UNION(_Table1,_Table2,_Table3,_Table4,_Table5),"_NUM",
    VAR _String = IF(CONTAINSSTRING([Times Called],"-"),"-","+")
    VAR _Num = SEARCH(_String,[Times Called],1,BLANK())
    RETURN
    VALUE(IFERROR(MID([Times Called],1,_Num-1),[Times Called])))
RETURN 
SELECTCOLUMNS(_UnionTable,[Times Called],"Sort1",RANKX(_UnionTable,[_NUM],,ASC))

The result is as follow:

vzhengdxumsft_0-1740036439875.png

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@AllisonB here it is:

 

Table = 
VAR __Table1 = SELECTCOLUMNS ( ADDCOLUMNS ( GENERATESERIES ( 1, 20, 1 ), "Times Called", FORMAT ( [Value], "" ) ), "Index", [Value], "Times Called", [Times Called] )
VAR __Table2 = ROW ( "Index", 21, "Times Called", "21-50" )
VAR __Table3 = ROW ( "Index", 51, "Times Called", "51-100" )
VAR __Table4 = ROW ( "Index", 101, "Times Called", "101-200" )
VAR __Table5 = ROW ( "Index", 201, "Times Called", "201+" )
RETURN 
UNION ( 
    __Table1,
    __Table2,
    __Table3,
    __Table4,
    __Table5
)

 

parry2k_0-1739987659893.png

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors