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
jdballard30
Helper II
Helper II

Generate a Table Containing Metadata About Other Tables

I've brought several tables of a CRM system data into Power BI, and I'd like to use Power BI (if it makes sense) to try and generate some statistics about each column of each table. For example, say that I've brought in the account table with the following data:

AccountId

AccountName

Address1

abc123

Acme Corp

123 Main Street

xyz456

WidgetCo

 

mno225

Joe's Appliances

15503 US Highway 27

 

I'd like to generate a table that looks like this, based on the above table:

TableName

FieldName

MaxLength

BlankValues

Account

AccountId

6

0

Account

AccountName

16

0

Account

Address1

19

1

 

Is something like this possible? If so, I can't wrap my head around how to do it.

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @jdballard30 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

Then you may create a blank query and input the following m codes in 'Advanced Editor'.

let
    Source = Table.FromRecords(
       {
           [TableName="Account"]
       }
    ),
    #"Added Custom" = Table.AddColumn(Source, "AccountName", each Table.ColumnNames(Table)),
    #"Expanded AccountName" = Table.ExpandListColumn(#"Added Custom", "AccountName"),
    #"Added Custom1" = Table.AddColumn(#"Expanded AccountName", "MaxLength", each if [AccountName]="AccountId"
then 
List.Max(
    List.Transform(
    Table.Column(Table,"AccountId"),
    each Text.Length(_)
    )
)
else if [AccountName]="AccountName"
then
List.Max(
    List.Transform(
       Table.Column(Table,"AccountName"),
       each Text.Length(Text.From(_)) 
    )
)
else if [AccountName]="Address1"
then
List.Max(
    List.Transform(
       Table.Column(Table,"Address1"),
       each Text.Length(Text.From(_)) 
    )
)
else 
null
),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "BlankValues", each let 
tab1 = Table.SelectRows(Table,each [AccountId]=""),
tab2 = Table.SelectRows(Table,each [AccountName]=""),
tab3 = Table.SelectRows(Table,each [Address1]="")
in
if [AccountName]="AccountId"
then 
Table.RowCount(
    tab1
)
else if [AccountName]="AccountName"
then
Table.RowCount(
    tab2
)
else if [AccountName]="Address1"
then
Table.RowCount(
    tab3
)
else 
null)
in
    #"Added Custom2"

 

Result:

c2.png

 

Best Regards

Allan

 

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

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @jdballard30 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

Then you may create a blank query and input the following m codes in 'Advanced Editor'.

let
    Source = Table.FromRecords(
       {
           [TableName="Account"]
       }
    ),
    #"Added Custom" = Table.AddColumn(Source, "AccountName", each Table.ColumnNames(Table)),
    #"Expanded AccountName" = Table.ExpandListColumn(#"Added Custom", "AccountName"),
    #"Added Custom1" = Table.AddColumn(#"Expanded AccountName", "MaxLength", each if [AccountName]="AccountId"
then 
List.Max(
    List.Transform(
    Table.Column(Table,"AccountId"),
    each Text.Length(_)
    )
)
else if [AccountName]="AccountName"
then
List.Max(
    List.Transform(
       Table.Column(Table,"AccountName"),
       each Text.Length(Text.From(_)) 
    )
)
else if [AccountName]="Address1"
then
List.Max(
    List.Transform(
       Table.Column(Table,"Address1"),
       each Text.Length(Text.From(_)) 
    )
)
else 
null
),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "BlankValues", each let 
tab1 = Table.SelectRows(Table,each [AccountId]=""),
tab2 = Table.SelectRows(Table,each [AccountName]=""),
tab3 = Table.SelectRows(Table,each [Address1]="")
in
if [AccountName]="AccountId"
then 
Table.RowCount(
    tab1
)
else if [AccountName]="AccountName"
then
Table.RowCount(
    tab2
)
else if [AccountName]="Address1"
then
Table.RowCount(
    tab3
)
else 
null)
in
    #"Added Custom2"

 

Result:

c2.png

 

Best Regards

Allan

 

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

Ajinkya369
Resolver III
Resolver III

Hi @jdballard30 ,

 

Yes it is possible using the Power query editor.All you have to do is go to query editor -> Create a new step by clicking on fx

And then type this Function: Table.Schema(Source)

Table.Schema(Source)Table.Schema(Source)

 

For Has Blank value use a condtional column Go to Add column -> Condtional Column

if account id equal = leave blank then output 1

if account name equal = leave blank then output 1

if address equal = leave blank then output 1

else = 0

Blank.JPG

 

If your problem is solved then accept this reply as a solution

 

Thank you

Ajinkya

Master Data Analysis - 

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.