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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
jayala
Frequent Visitor

Dynamic Table Calculation

Hello guys, I am here again looking for your help.

 

I have a dataset with a column called Company Group.

 

I would like to build a new table based on that column only with the distinct values and an additional row "Total". I need also another column as an Index.

 

This is what I tried but it didn't work.

 

VAR companies = UNION(CALCULATETABLE(DISTINCT(DB[Company Group])),{("TOTAL")})
VAR index = GENERATESERIES(1, DISTINCTCOUNT(DB[Company Group])+1)
VAR _all =
GENERATE(companies1, index)
return _all
 
 
 
My desired outcome is something like:
 
Company | ID
Company1 | 1
Company2 | 2
Company3 | 3
TOTAL | 4
 
Can you guys provide me some help?
Thank you in advance!
 
Sample data:
Screenshot_2.png

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jayala ,

You can create a new table with the following formula:

newCompany = ADDCOLUMNS(DISTINCT('Company'[Company Group]),"Index",RANKX(ALL('Company'),'Company'[Company Group],,ASC,Dense))

newCompany.JPG

Best Regards

Rena

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

Sample data please. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, thanks for your reply.

 

Please find a screenshot in the main post with sample data.

 

 

Anonymous
Not applicable

Hi @jayala ,

You can create a new table with the following formula:

newCompany = ADDCOLUMNS(DISTINCT('Company'[Company Group]),"Index",RANKX(ALL('Company'),'Company'[Company Group],,ASC,Dense))

newCompany.JPG

Best Regards

Rena

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.