Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

[Power Query] Check which column names equal a [Column] for a conditional column

Hi, I can´t figure out this. I´ve looked in the forum but didn´t found an answer either. Given a table like this: I´d like to check which [Year] equals to a column name in the table, and then...
  • Zubair_Muhammad's avatar
    7 years ago

    Hi Anonymous 

     

    First add an Index Column Starting from 0

     

    Then you can use this Custom Column from Query Editor

     

    =let mycolumn=Text.From([Year]) in
    Table.Column(#"Added Index",mycolumn){[Index]}*[Value]
  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    7 years ago

    SureAnonymous

     

    Let me tell you first that there is an even easier solution which doesn't even require to Add an Index Column.

    Sorry it didn't occur to me first

    Just Add this custom column. It should give you desired result

     

    =Record.Field(_,Text.From([Year]))*[Value]

    _  gets you the current row record. Second argument is the fieldname from which you want to fetch the value

    https://docs.microsoft.com/en-us/powerquery-m/record-field