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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
txfrogg1982
New Member

Reference a Row In Another Column

How do I reference data in a row of a column and place it in a new column all on the same table?

 

Column A             Column B

Data 1                    Data 3

Data 2                    Data 3

Data 3                    Data 3

1 ACCEPTED SOLUTION

Hi @txfrogg1982 ,

Based on your description and expected output, one thing I could not understand is you have the same value for Data 1,2,3 but how could column B only show values in the first two rows.

If this is your final expected result, maybe you need an index column, create an index column in power query editor, close and apply it, create this calculated column:

Column B2 = 
IF(
    [Index] <= 2,
    CALCULATE(
        MAX('Table'[Column A]),
        FILTER(
            ALL('Table'),
            'Table'[Rank] = MAX('Table'[Rank])
        )
    ),
    BLANK()
)

If both Data 1 and Data 2 rows have Data 3, create this calculated column without index column:

Column B = 
IF(
    [Rank] <> MAX('Table'[Rank]),
    CALCULATE(
        MAX('Table'[Column A]),
        FILTER(
            ALL('Table'),
            'Table'[Rank] = MAX('Table'[Rank])
        )
    ),
    BLANK()
)

rank.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

5 REPLIES 5
amitchandak
Super User
Super User

@txfrogg1982 , The information you have provided is not making the problem clear to me. Can you please explain with an example.

 

Looking at column B you can get like

Column B = max([Column A])


Appreciate your Kudos.


edhans
Super User
Super User

You will need to be a bit clearer in your request, and please use tables to put in data. We cannot use text in the post as samples as it takes time to get rid of the line feeds and spaces. See link at bottom.

 

But, you can reference other columns. In Power Query, you can add a new custom column with the following formula:

List.Max(Source[Column A])

Source is the step above the one you are in, so in my case, I only had a Source step. It could be #"Changed Step" or whatever. So it looks at the table called "Source" (power query steps are really tables, or lists or some other object) and then [Column A] and gets the max value, so now Data 3 is in all rows of the new column.

edhans_0-1599259358587.png

In DAX, the following measure will add a new column to a table visual.

New Column for Table Visual = 
CALCULATE(
    MAX('Data Table'[Column A]),
    REMOVEFILTERS('Data Table'[Column A])
)

So you get this:

edhans_1-1599259565245.png

 

I'm not going to show you how to do a calculated column, because you shouldn't use those. 😉

In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables
SQLBI Video on Measures and Calculated Columns

 

 

 

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Greg_Deckler
Super User
Super User

@txfrogg1982 - Depends, you have to have some way to reference it like an Index or something or perhaps it is the MIN or MAX of that column. 

 

Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I used the RANKX function to get the Rank column, so "Column A" and "Rank" is my current state. I want a new column(Column B), where I only have "Data 3" from "Column A". I'm have trouble writing DAX that will get me to the desired state, "Column B". Any help will be much appreciated.

 

Column A    Rank    Column B

Data 1          1          Data 3

Data 2          2          Data 3

Data 3          3

Data 1          1

Data 2          2

Data 3          3

 

Hope this gives some more clarity.

Hi @txfrogg1982 ,

Based on your description and expected output, one thing I could not understand is you have the same value for Data 1,2,3 but how could column B only show values in the first two rows.

If this is your final expected result, maybe you need an index column, create an index column in power query editor, close and apply it, create this calculated column:

Column B2 = 
IF(
    [Index] <= 2,
    CALCULATE(
        MAX('Table'[Column A]),
        FILTER(
            ALL('Table'),
            'Table'[Rank] = MAX('Table'[Rank])
        )
    ),
    BLANK()
)

If both Data 1 and Data 2 rows have Data 3, create this calculated column without index column:

Column B = 
IF(
    [Rank] <> MAX('Table'[Rank]),
    CALCULATE(
        MAX('Table'[Column A]),
        FILTER(
            ALL('Table'),
            'Table'[Rank] = MAX('Table'[Rank])
        )
    ),
    BLANK()
)

rank.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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