cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Jonas_Jordao
Frequent Visitor

Custom Column with column names that have null registers

Hello everybody. I need some help here with a customer request.

My database is one that has several columns, including columns with the names of documents that the supplier needs to deliver to complete the registration process.

The client asked me to put a column with the documents that the supplier must deliver, so, I need a column that contains the name of the columns where the record of that line is null. As in DAX it is not possible to bring the column name, it needs to be in Power Query, and I'm having a lot of difficulties to do that.

Below is an example of the base and the expected result in the column "Documents Missing".

Thank you for the help

 

SupplierDateStatusDoc 1Doc 2Doc 3Doc 4Doc 5 Documents Missing
Mr. Johnjan/22ActiveokokokokokNone
Mr. Davefev/22Pendindok okok Doc 2; Doc 5
Ms. Clairemar/22ActiveokokokokokNone
Ms. Marieabr/22Pendindok    Doc 2; Doc 3; Doc 4; Doc 5
Mr. Kevinjan/22Pendind  ok  Doc 1; Doc 2; Doc 4; Doc 5
Mr. Carlfev/22Pendindokokokok Doc 5
Ms. Evamar/22ActiveokokokokokNone

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jonas_Jordao 

 

I have pasted the Advanced Editor code below

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8i3SU/DKz8hT0lHKSszTNzICMhyTSzLLUoGM/GysRKwORJ9LIlhVWmoZRF9Aal5KZl4KTKUCij4FiLZiPQXnnMTMIpDG3MQiEiwE6vRNLMoEKUtMKsJpIwLDnOmdWpaJ4j+ELgVkZ6Lqck4sysHjOTQC4TvXskSSvBYLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Supplier = _t, Date = _t, Status = _t, #"Doc 1" = _t, #"Doc 2" = _t, #"Doc 3" = _t, #"Doc 4" = _t, #"Doc 5 " = _t]),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Supplier", "Date", "Status"}, "Attribute", "Value"),
#"Added Conditional Column" = Table.AddColumn(#"Unpivoted Columns", "Document Missing", each if [Value] <> "ok" then [Attribute] else null),
#"Grouped Rows" = Table.Group(#"Added Conditional Column", {"Supplier"}, {{"Grouped Table", each _, type table [Supplier=nullable text, Date=nullable text, Status=nullable text, Attribute=text, Value=text, Custom=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Documents Missing", each Table.Column([Grouped Table],"Document Missing")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Documents Missing", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Expanded Grouped Table" = Table.ExpandTableColumn(#"Extracted Values", "Grouped Table", {"Date", "Status", "Attribute", "Value"}, {"Date", "Status", "Attribute", "Value"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Grouped Table",{"Supplier", "Date", "Status", "Documents Missing", "Attribute", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Reordered Columns", List.Distinct(#"Reordered Columns"[Attribute]), "Attribute", "Value"),
#"Replaced Value" = Table.ReplaceValue(#"Pivoted Column","","None",Replacer.ReplaceValue,{"Documents Missing"})
in
#"Replaced Value"

 

This is what i got

esha_shah2002_0-1653650420741.png

 

If this post helps, Accept it as a solution

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Jonas_Jordao 

 

I have pasted the Advanced Editor code below

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8i3SU/DKz8hT0lHKSszTNzICMhyTSzLLUoGM/GysRKwORJ9LIlhVWmoZRF9Aal5KZl4KTKUCij4FiLZiPQXnnMTMIpDG3MQiEiwE6vRNLMoEKUtMKsJpIwLDnOmdWpaJ4j+ELgVkZ6Lqck4sysHjOTQC4TvXskSSvBYLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Supplier = _t, Date = _t, Status = _t, #"Doc 1" = _t, #"Doc 2" = _t, #"Doc 3" = _t, #"Doc 4" = _t, #"Doc 5 " = _t]),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Supplier", "Date", "Status"}, "Attribute", "Value"),
#"Added Conditional Column" = Table.AddColumn(#"Unpivoted Columns", "Document Missing", each if [Value] <> "ok" then [Attribute] else null),
#"Grouped Rows" = Table.Group(#"Added Conditional Column", {"Supplier"}, {{"Grouped Table", each _, type table [Supplier=nullable text, Date=nullable text, Status=nullable text, Attribute=text, Value=text, Custom=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Documents Missing", each Table.Column([Grouped Table],"Document Missing")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Documents Missing", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Expanded Grouped Table" = Table.ExpandTableColumn(#"Extracted Values", "Grouped Table", {"Date", "Status", "Attribute", "Value"}, {"Date", "Status", "Attribute", "Value"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Grouped Table",{"Supplier", "Date", "Status", "Documents Missing", "Attribute", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Reordered Columns", List.Distinct(#"Reordered Columns"[Attribute]), "Attribute", "Value"),
#"Replaced Value" = Table.ReplaceValue(#"Pivoted Column","","None",Replacer.ReplaceValue,{"Documents Missing"})
in
#"Replaced Value"

 

This is what i got

esha_shah2002_0-1653650420741.png

 

If this post helps, Accept it as a solution

Yeah, it worked perfectly. Thanks a lot for the help.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors