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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Shamank77
New Member

want to create a column that meets your requirements

As shown in the attachment, there are three columns: name, parent_name and serial number column ID. Now I want to create a new column parent_id.

The number in the serial number column is automatically displayed based on the relationship between the NAME column and the PARENT_NAME column. For the expected result, see the attachment.

So don't know how the DAX text that creates such a column should be written in PowerBi

 

nameparent_nameidparent_id      
AH18      
BH28      
CH38      
DG47      
EC53      
FG67      
GE75      
H 8       
          
1 ACCEPTED SOLUTION

Hi, @Shamank77

According to your description, You want to show [parent_id] corresponding to [parent_name] according to the relationship between [name] and [id]. Right?

 

Here are the steps you can follow :

(1)This is my test data:

vyueyunzhmsft_2-1662434942556.png

 

(2)We can create a calculated column: “parent_id”:

parent_id =
VAR _table =
    SELECTCOLUMNS ( 'Table', "Name", [name], "id", [id] )
RETURN
    MAXX ( FILTER ( _table, [name] = EARLIER ( 'Table'[parent_name] ) ), [id] )

 

 

(3)Then we can meet your need , the result is as follows:

vyueyunzhmsft_3-1662434979348.png

 

Best Regards,

Aniya Zhang

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

7 REPLIES 7
tamerj1
Super User
Super User

Hi @Shamank77 

You may also try

parent_id =
CALCULATE (
    SELECTEDVALUE ( TableName[id] ),
    TREATAS ( VALUES ( TableName[parent_name] ), TableName[name] )
)

Hi @tamerj1 

 

Thanks for your suggestion 😊

I tried to make the DAX as :

parent_id =
CALCULATE (
    SELECTEDVALUE ( TableName[id] ),
    TREATAS ( VALUES ( TableName[parent_name] ), TableName[name] )
)

 but the result became 

nameparent_nameidparent_id sampleparent_id
AH18 
BH28 
CH383
DG47 
EC535
FG67 
GE757
H 8 8

 

@Shamank77 

Please try

parent_id =
CALCULATE (
    SELECTEDVALUE ( TableName[id] ),
    TREATAS ( VALUES ( TableName[parent_name] ), TableName[name] ),
    REMOVEFILTERS ( TableName )
)
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached file.

It is for creating a new column.

 

Jihwan_Kim_0-1662433291295.png

 

 

Parend_id CC = 
LOOKUPVALUE('Table'[id],'Table'[name],'Table'[parent_name])

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi, @Shamank77

According to your description, You want to show [parent_id] corresponding to [parent_name] according to the relationship between [name] and [id]. Right?

 

Here are the steps you can follow :

(1)This is my test data:

vyueyunzhmsft_2-1662434942556.png

 

(2)We can create a calculated column: “parent_id”:

parent_id =
VAR _table =
    SELECTCOLUMNS ( 'Table', "Name", [name], "id", [id] )
RETURN
    MAXX ( FILTER ( _table, [name] = EARLIER ( 'Table'[parent_name] ) ), [id] )

 

 

(3)Then we can meet your need , the result is as follows:

vyueyunzhmsft_3-1662434979348.png

 

Best Regards,

Aniya Zhang

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

Hi ,Miss Zhang

Thanks for your suggestion~

The result is up to the mustard exactly

Yes,it works!Thank you very much indeed😄

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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