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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Gangsta
Frequent Visitor

Add column to Power Bl tab where value is from another row in table where 3 columns match criteria

In the table below, records 1,2,3,5 DAX formula copies city names from Town to the Missing Town as data was already available.

 

       New Column
NumberFirst NameSecond NameBirthdayVisitsDistinctTownMissing Town
1JackDee16/06/201102LondonLondon
2PaulJacob01/07/201401ParisParis
3PeterJames07/03/201512MadridMadrid
4ViktorsThomas27/12/200811  
5ElianaPlumb05/02/201211MiamiMiami
6KausarDefoe10/10/200801  
7KhadijaSingh19/11/201111TokyoMiami
8KrishKing24/07/200801  
9IbrarPlaice02/09/201111  
10NashChow07/05/200801  
11JackDee16/06/201112 London
12AhmadSantosh19/02/200801  
13PeterJames07/03/201502  

 

records 4,6,8,9,10,12 and 13 do not have the Town and as there are no other matching records with Town that meet the 3 criteria First Name, Second name and Birthday , so DAX formula will leave them empty on the Missing Town Column, unless we can find another record that matches the 3 cirtiera.

 

DAX formula is needed for 'Missing Town' column so Record 11 can pull Town into the Missing Town column from record 1 that matches the 3 criteria which has the Town.

 

Hope that helps claridy what I am trying to do, bnasicall pupulating a colum if the data is available in one ofthe other records in the table if 3 criteria are met.

 

3 ACCEPTED SOLUTIONS
v-jiewu-msft
Community Support
Community Support

Hi @Gangsta ,

Based on my testing, please try the following DAX formula:

1.Create the new column.

Missing Town = 
VAR CurrentFirstName = 'Table'[First Name]
VAR CurrentSecondName = 'Table'[Second Name]
VAR CurrentBirthday = 'Table'[Birthday]
RETURN
    CALCULATE(
        MAX('Table'[Town]),
        FILTER(
            'Table',
            'Table'[First Name] = CurrentFirstName &&
            'Table'[Second Name] = CurrentSecondName &&
            'Table'[Birthday] = CurrentBirthday &&
            'Table'[Town] <> BLANK()
        )
    )

2.The result is shown below.

vjiewumsft_0-1721894379451.png

 

Best Regards,

Wisdom Wu

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

Hi @Gangsta ,

Based on my testing, please try the following DAX formula:

1.Create the new column.

Missing Town = 
VAR CurrentFirstName = 'Table'[First Name]
VAR CurrentSecondName = 'Table'[Second Name]
VAR CurrentBirthday = 'Table'[Birthday]

VAR FindMaxVisits =
    CALCULATE(
        MAX('Table'[Visits]),
        ALLEXCEPT('Table', 'Table'[First Name], 'Table'[Second Name], 'Table'[Birthday]),
        'Table'[Town] <> BLANK()
    )
VAR FindTownWithMaxVisits =
    CALCULATE(
        MAX('Table'[Town]),
        //FIRSTNONBLANK('Table'[Town], 1),
        FILTER(
            'Table',
            'Table'[First Name] = CurrentFirstName &&
            'Table'[Second Name] = CurrentSecondName &&
            'Table'[Birthday] = CurrentBirthday &&
            'Table'[Visits] = FindMaxVisits
        )
    )
RETURN
IF(
    'Table'[Town] <> BLANK(),
    'Table'[Town], 
    FindTownWithMaxVisits
)

2.The result is shown below.

vjiewumsft_0-1721958052464.png

 

Best Regards,

Wisdom Wu

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

Thanks @v-jiewu-msft, I will try this on the report and get back to you, again appreciate your help.

View solution in original post

6 REPLIES 6
v-jiewu-msft
Community Support
Community Support

Hi @Gangsta ,

Based on my testing, please try the following DAX formula:

1.Create the new column.

Missing Town = 
VAR CurrentFirstName = 'Table'[First Name]
VAR CurrentSecondName = 'Table'[Second Name]
VAR CurrentBirthday = 'Table'[Birthday]
RETURN
    CALCULATE(
        MAX('Table'[Town]),
        FILTER(
            'Table',
            'Table'[First Name] = CurrentFirstName &&
            'Table'[Second Name] = CurrentSecondName &&
            'Table'[Birthday] = CurrentBirthday &&
            'Table'[Town] <> BLANK()
        )
    )

2.The result is shown below.

vjiewumsft_0-1721894379451.png

 

Best Regards,

Wisdom Wu

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

 

Sorry I have 1 further requirement, sorry for pushing my luck but it would be great if the DAX column called Missing Town also did  the following, 

 

If the Town is known, then that should be copied to Missing Town, only if the Town is unknown it proceeds to solution provided, but if the solution can now check if ther are multiple other records that have the town, then the record that has most visits where the town is copied from.

 

In the below updated table

Green records copied over the town to New town since the Town was already know

Red Records there were two for the same person, number 1 had the Town, number 11 did not, so it was copied from 1, as per the existing solution.

 

Now there are 3 records for Peter James 3, 9 and 13, 3 has the town so it is copied to Missing Town as Madrid.  Number 9 also has the Town Beijing, this is copied to Missing Town.  Number 13 does not have the Town, there are two choices for the Missing Town, either Madrid or Beijing, we want to copy the one with the most visits, so Beijing is copied as that has 3 visits.   

 

       New Column
NumberFirst NameSecond NameBirthdayVisitsDistinctTownMissing Town
1JackDee16/06/201102LondonLondon
2PaulJacob01/07/201401ParisParis
3PeterJames07/03/201513MadridMadrid
4ViktorsThomas27/12/200811  
5ElianaPlumb10/08/201511MiamiMiami
6KausarDefoe10/10/200801  
7KhadijaSingh24/05/201511TokyoTokyo
8KrishKing24/07/200801  
9PeterJames07/03/201543BeijingBeijing
10NashChow07/05/200801  
11JackDee16/06/201112 London
12AhmadSantosh19/02/200801  
13PeterJames07/03/20150  Beijing

 

Would be great if this adjustment can be made. 

 

Thanks again,

Hi @Gangsta ,

Based on my testing, please try the following DAX formula:

1.Create the new column.

Missing Town = 
VAR CurrentFirstName = 'Table'[First Name]
VAR CurrentSecondName = 'Table'[Second Name]
VAR CurrentBirthday = 'Table'[Birthday]

VAR FindMaxVisits =
    CALCULATE(
        MAX('Table'[Visits]),
        ALLEXCEPT('Table', 'Table'[First Name], 'Table'[Second Name], 'Table'[Birthday]),
        'Table'[Town] <> BLANK()
    )
VAR FindTownWithMaxVisits =
    CALCULATE(
        MAX('Table'[Town]),
        //FIRSTNONBLANK('Table'[Town], 1),
        FILTER(
            'Table',
            'Table'[First Name] = CurrentFirstName &&
            'Table'[Second Name] = CurrentSecondName &&
            'Table'[Birthday] = CurrentBirthday &&
            'Table'[Visits] = FindMaxVisits
        )
    )
RETURN
IF(
    'Table'[Town] <> BLANK(),
    'Table'[Town], 
    FindTownWithMaxVisits
)

2.The result is shown below.

vjiewumsft_0-1721958052464.png

 

Best Regards,

Wisdom Wu

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

Thanks @v-jiewu-msft, I will try this on the report and get back to you, again appreciate your help.

Just wanted give a huge thanks, your solution worked perfectly without any changes needed so have marked it as the solution.  You saved me alot of time especially as I was not sure how to  phrase it in my question being new to DAX I dont know all the various possible methods, the onese I was trying were compledtelty different to your appraoch so foes without saying you helped me incrfease my understanding, but still long way to go, thank you.

FreemanZ
Super User
Super User

hi @Gangsta ,

 

try like:

Column =
VAR _table =
CALCULATEDTABLE(
    data,
    ALLEXCEPT(data, [First Name], [Second Name], [Birthday])
)
VAR _town = MAXX(_table, data[Town])
RETURN _town

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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