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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 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.

Top Solution Authors
Top Kudoed Authors