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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors