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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Nikhil_567
Frequent Visitor

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
1 ACCEPTED SOLUTION

Hi @Nikhil_567 ,

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"

vyiruanmsft_0-1714033387548.png

Best Regards

Community Support Team _ Rena
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
Uzi2019
Super User
Super User

Hi @Nikhil_567 

Try below dax for  calculated column 

Uzi2019_0-1712305421125.png

 

 

Final = IF(AttributeDS[Attributes]="Indication",AttributeDS[Indication],""&AttributeDS[SKU])
 
Dont take measure.
 
I hope I answered your question!
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Thanks @Uzi2019 

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

@Uzi2019 Thanks for your contribution on this thread.

 

Hi @Nikhil_567 ,

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

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

hi @v-yiruan-msft ,

Clarifying on the requirement below.

We have a main table with below three columns-

DataSourceIndicationSKU
AX1
B 3
CY 

 

Now we have got a mapping table, in which Attribite columns consists of column names from main table (shared above) which we need to map against data source

 

DataSourceAttribute
AIndication
ASKU
BSKU
CIndication

 

Expected Result-

We are trying to calculate a new column in the main table, where we are using Attribute column from the mapping table to get the correspondig values in the new column dynamically against the respective DataSource from the column names mentioned in the Attribute column of mapping table.

 

DataSourceIndicationSKUCalculatedColumn
AX1X
AX11
B 33
CY Y

 

I hope I was able to explain you the situation.

Let me know incase any further clarification is required.

 

@Greg_Deckler @Ritaf1983 Can you please take a look and help me out here.

 

 

 

Hi @Nikhil_567 ,

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"

vyiruanmsft_0-1714033387548.png

Best Regards

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.