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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
tmhalila
Resolver II
Resolver II

Create category based on column names of the table

Hello,

I need your help here I have a table with two columns that are supposed to be categories, and its total makes another column named total_participants

sample data

tmhalila_0-1700965205980.png

 

Expected output

tmhalila_3-1700966557551.png

 

I want to use this with the decomposition tree visual, so it can start with total the decomposition into category_1 and category_2. How can I do this only with either a calculated column or a measure without adding a calculated table due to the huge dataset I have? @Greg_Deckler  I saw your suggestion somewhere for using only SWITCH(TRUE() can you assist, please?

 



 

2 REPLIES 2
danextian
Super User
Super User

Hi @tmhalila 

You can unpivot Category_1 and Category_2 columns and that should create a column of categories. That should be the simplest solution. If for some reason, you don't want that route, you can create a disconnected table that holds the category names either in DAX or M (sample below) and create a measure to return the value for each category.

CategoryTable =
DATATABLE ( "Category", STRING, { { "Category 1" }, { "Category 2" } } )


Measure:

Value =
SWITCH (
    SELECTEDVALUE ( CategoryTable[Category] ),
    "Category 1", SUM ( 'FactTable'[Category 1] ),
    "Category 2", SUM ( 'FactTable'[Category 2] )
)

Use the category column from the disconnected table in the decomposition tree visual.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks for your solution @danextian 

I am trying to avoid Unpivot and additional of the table for the two reasons; 

  • The dataset has millions of records and keeps coming, to unpivot it may lead to additional rows
  • The dataset has more sets of categories like the one shared so it will be confusing when trying to unpivot different sets.

So I think using a calculated column or measure can at least save performance.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors