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
acarto
Frequent Visitor

fix hierarchy in custom column

Hello,

 

The data I have is following this structure:
Column1 Column 2
A              alfa

A              beta

B              gamma

B              delta
alfa          epsilon  

The column I need to create would be Column3 with the conditioning: if Column2 value is contained in Column 1, then I want to display column 2. The problem is to display it for the row 1, so I can keep the hierarchy. 

Column1 Column 2 Column3
A              alfa         epsilon

A              beta        blank()

alfa          epsilon    blank()

 

Is there any posibility to have this?

Thank you in advance for helping me.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @acarto ,
Thanks for @rajendraongole1  reply.
Here is what i want to add

vheqmsft_0-1718867520586.png

Create a coumn

Column = 
VAR  _currentrow = 'Table'[Subcategory]
VAR _vtable = FILTER(CROSSJOIN(ALLSELECTED('Table'),SELECTCOLUMNS(ALLSELECTED('Table'),"_1",'Table'[Category],"_2",'Table'[Subcategory])),[Category]=[_2])
RETURN MAXX(FILTER(_vtable,[_2]=_currentrow),[Subcategory])

Final output

vheqmsft_1-1718867556318.png

 

Best regards,
Albert He

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @acarto ,
Thanks for @rajendraongole1  reply.
Here is what i want to add

vheqmsft_0-1718867520586.png

Create a coumn

Column = 
VAR  _currentrow = 'Table'[Subcategory]
VAR _vtable = FILTER(CROSSJOIN(ALLSELECTED('Table'),SELECTCOLUMNS(ALLSELECTED('Table'),"_1",'Table'[Category],"_2",'Table'[Subcategory])),[Category]=[_2])
RETURN MAXX(FILTER(_vtable,[_2]=_currentrow),[Subcategory])

Final output

vheqmsft_1-1718867556318.png

 

Best regards,
Albert He

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

Thank you very much @Anonymous ! it work wonderfully!! 😊

rajendraongole1
Super User
Super User

Hi @acarto - Used your tables, 

 

I have created in table 2 with Index column (Unique row identifier) and create a calculated column in Table 2 as below

 

Column3 =
VAR CurrentValue = 'Tab2'[Column2]
VAR RowNumber = 'Tab2'[Index] // Assuming you have a unique row identifier
RETURN
IF (
    COUNTROWS (
        FILTER (
            'Tab2',
            'Tab2'[Column1] = CurrentValue
        )
    ) > 0 &&
    'Tab2'[Column1] <> CurrentValue,
    IF (
        MINX(
            FILTER (
                'Tab2',
                'Tab2'[Column1] = EARLIER('Tab2'[Column1]) &&
                'Tab2'[Column2] = EARLIER('Tab2'[Column2])
            ),
            'Tab2'[Index]
        ) = RowNumber,
        CurrentValue,
        BLANK()
    ),
    BLANK()
)
 
rajendraongole1_0-1717768275348.png

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





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

Proud to be a Super User!





I very much appreciate your answer, but it does not solve the issue.

 

Maybe I didn't explain myself properly, the thing is that I have a 2 level hierarchy in only 2 columns not 3 as it should.


First level: A - alfa

First level: A - beta

Second level: alfa - epsilon

 

So the solution should be:

A - alfa - epsilon

A - beta - blank()

 

I'm just unable to relate the epsilon with the A - alfa just because the alfa is repeted in Column1 and Column 2

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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