Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Create a Dynamic Column Based On Other Column Values

Hi Team,

 

We have a requirement wherein we need to create a new column using existing 3 columns from the same table.

Input Table-

DataSourceIndicationSKUDataSource_MappingAttributes
AX1AIndication
AX1ASKU
B 3BSKU
CY CIndication

 

Expected Result-

We want this to be dynamically calculated (not statically) using Attributes column values so that Indication & SKU Column values gets populated against the DataSource

DataSourceIndicationSKUDataSource_MappingAttributesCalculated Column
AX1AIndicationX
AX1ASKU1
B 3BSKU3
CY CIndicationY
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

    Please apply the below codes for the main table in Power Query Editor and check if it can return your expected result...

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUYoAYkOlWJ1oJScgC4iMwRxnICsSJBAbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DataSource = _t, Indication = _t, SKU = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"DataSource", type text}, {"Indication", type text}, {"SKU", Int64.Type}}),
        #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"Indication", "SKU"}, "Attribute", "Value"),
        #"Filtered Rows" = Table.SelectRows(#"Unpivoted Only Selected Columns", each ([Value] <> ""))
    in
        #"Filtered Rows"

    Best Regards

5 Replies

  • Uzi2019's avatar
    Uzi2019
    Community Champion

    Hi Anonymous 

    Try below dax for  calculated column 

     

     

    Final = IF(AttributeDS[Attributes]="Indication",AttributeDS[Indication],""&AttributeDS[SKU])
     
    Dont take measure.
     
    I hope I answered your question!
     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Uzi2019 

      We didn't want indication column to be hard-coded. 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Uzi2019 Thanks for your contribution on this thread.

         

        Hi Anonymous ,

        The formula supplied by Uzi2019 was intended to facilitate the attainment of the expected outcome, however, it appears that it has not met the objective. Could you please provide additional clarification on the below sentence? It would be greatly appreciated if you could supplement your explanation with more sample data and expound on the underlying logic.


        We didn't want indication column to be hard-coded. 


        Best Regards