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
EaglesTony
Post Prodigy
Post Prodigy

How can I get a table to collapse so certain columns only appear when they change

I have the following table:

 

AREA        DOMAIN    SUBDOMAIN     TEACHER    ASSISTANT

1               1                 1                        Joe             Karen

1               1                 2                       Frank          Tom

1               2                 7                       Mia             Bobby

2               3                 4                       Lori             Karen

2               3                 5                       Mia             Frank

2               4                 9                       Mary          Adam

 

I'm trying to get it so AREA/DOMAIN/SUBDOMAIN dont repeat so it looks like:

AREA        DOMAIN    SUBDOMAIN     TEACHER    ASSISTANT

1               1                 1                        Joe             Karen

                                    2                       Frank          Tom

1               2                 7                       Mia             Bobby

2               3                 4                       Lori             Karen

                                    5                       Mia             Frank

                 4                 9                       Mary          Adam

 

 

1 ACCEPTED SOLUTION

I had to do something like this:

 

= Table.AddColumn(AddIndex, "AREA_Display", each
if [Index] = 0 then Text.From([AREA])
else if [AREA] = AddIndex{[Index]-1}[AREA] then null
else Text.From([AREA]))

 

if [Index] = 0 then Text.From([Domain])
else if
[AREA] = AddIndex{[Index]-1}[AREA] and
[Domain] = AddIndex{[Index]-1}[Domain]
then null
else Text.From([Domain])

 

then finally added:

= Table.AddColumn(#"Reordered Columns", "Level", each if [AREA] <> null and [DOMAIN] <> null and [SUBDOMAIN] <> null then 1 else if [DOMAIN] <> null and [SUBDOMAIN] <> null then 2 else if [SUBDOMAIN] <> null then 3 else 999)

View solution in original post

29 REPLIES 29

Getting this error:

EaglesTony_0-1752513927876.png

 

That's because when Power Query couldnt find the previous step 'AddIndex' because it either doesn’t exist yet or is being referenced before it was created.

 

I'd suggest you copy and paste my entire M codes into a new 'blank query' and understand the logic of each step. Once you got this you can adjust your code either through UI or Query editor 🙂 

Here is an example (In this case since Area and Domain are the same, then it only shows once and doesn't repeat)

 

AREA        DOMAIN    SUBDOMAIN     TEACHER    ASSISTANT

1               1                 1                        Joe             Karen

                                    2                       Frank          Tom

@EaglesTony then reshaping them in Power Query is the right solution, isnt it? btw you may need to use table in reporting. 

I can group them in PowerQuery, but it repeats the Domain and SubDomain.

@EaglesTony 

Can you show me your Grouped results and be more specific on how these two are repeating? 

I group by Area,Domain,SubDodomain and it does the grouping correctly, but the results are:

 

AREA        DOMAIN    SUBDOMAIN     TEACHER    ASSISTANT

1               1                 1                        Joe             Karen

1               1                 2                       Frank          Tom

1               2                 7                       Mia             Bobby

2               3                 4                       Lori             Karen

2               3                 5                       Mia             Frank

2               4                 9                       Mary          Adam

 

So the first 3 columns solves the group, but the 3 columns mentioned are repeated, so it should show the first time those columns, but next one that is similiar, leave that blank.

 

What I am wondering is if I can somehow have another column such as 

AREA        DOMAIN    SUBDOMAIN     TEACHER    ASSISTANT   LEVEL

1               1                 1                        Joe             Karen             1

1               1                 2                       Frank          Tom                2

1               2                 7                       Mia             Bobby            1 

2               3                 4                       Lori             Karen             1 

2               3                 5                       Mia             Frank             2

2               4                 9                       Mary          Adam             1

 

Then do some logic if not level 1, replace the column value with blank.

@EaglesTony 

Did you try the initial approach i offered step by step in this thread? 

You would need to add 3 separate Custom columns for 'AREA, 'DOMAIN', 'SUBDOMAIN' each to make repeating rows null by M coding. 

They are blank when duplicated

 

image.png

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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