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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Count

Hi 

 

I have 2 tables that have 200 coulmns each. 

I need to count a specific text like "TRUE" on each column and shown under of each column. 

how can i do that ? 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I have created a sample for your reference, please check the following steps as below.

1. Dupilcate your table and transform it like that. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZVAxDsIwEPsKurlD09DcZSwIBpBAoA5A1B907f+xQ1AqGHyxzr5zkpTESSMD8AC6DsWxE9ogU5OEjR3wBHxg8VTVZZV8X+Yvyzz/HLRsa+8KmKGoovSgNPTgx2oKHIiRzH9CmHr6CzgM6xStwp27uXQc1w7mnjflvqb5JXSpxawz8QXcvt9Q1lkLfXoD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, #"Country " = _t, #"City " = _t, #"Street " = _t, #"House " = _t, #"Unit " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Country ", type text}, {"City ", type text}, {"Street ", type text}, {"House ", type text}, {"Unit ", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] = "Null")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Attribute"}, {{"Count", each Table.RowCount(_), type number}}),
    #"Transposed Table" = Table.Transpose(#"Grouped Rows"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Street ", Int64.Type}, {"House ", Int64.Type}, {"Unit ", Int64.Type}, {"Country ", Int64.Type}, {"City ", Int64.Type}})
in
    #"Changed Type1"

  2.PNG

 

2. Append tables to get the excepted result.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZVAxDsIwEPsKurlD09DcZSwIBpBAoA5A1B907f+xQ1AqGHyxzr5zkpTESSMD8AC6DsWxE9ogU5OEjR3wBHxg8VTVZZV8X+Yvyzz/HLRsa+8KmKGoovSgNPTgx2oKHIiRzH9CmHr6CzgM6xStwp27uXQc1w7mnjflvqb5JXSpxawz8QXcvt9Q1lkLfXoD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, #"Country " = _t, #"City " = _t, #"Street " = _t, #"House " = _t, #"Unit " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Country ", type text}, {"City ", type text}, {"Street ", type text}, {"House ", type text}, {"Unit ", type text}}),
    #"Appended Query" = Table.Combine({#"Changed Type", #"Table (3)"})
in
    #"Appended Query"

Capture.PNG

 

 

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

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

So you want to add this count of TRUE as a row to your table?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

yes, exactly 

OK, that's doable. The basic technique is that you are going to create a separate branch in your M code query and then use table appending to squash the two branches together. Let me throw together an example.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

OK, here is what I did PBIX attached.

 

Look! Look! @ImkeF !! I solved a slightly harder than trivial Power Query problem and I didn't even have to bug you!!!! 🙂

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg 

thansk for that, I couldn't understand what happened 

I have enclosed a sample excel file.

tabel 1

IDCarestateSellerSellCountry
1BMWNSWALI $        22,000A
2VolvoVICHELLEN $        25,000B
3HYNSWALI Null C
4BenzNSWALI $        55,000Null
5NullNullNull $        65,000F
6BMWSAFRED Null J
7KIAVICHELLEN $        75,000Null
8HYNullNull $        85,000
9NullNSWALI Null Z

tabel2 

IDCountry City Street House Unit 
1AX2211606
2BY3633671
3CANullNullNull
4NullO8877588
5FNull6499631
6JNullNullEANull
7NullR55TTNull
8C87335789
9ZQ22Null809

could you please show how many NULL we have on each column?

thanks for that 

 

Hi @Anonymous ,

 

I have created a sample for your reference, please check the following steps as below.

1. Dupilcate your table and transform it like that. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZVAxDsIwEPsKurlD09DcZSwIBpBAoA5A1B907f+xQ1AqGHyxzr5zkpTESSMD8AC6DsWxE9ogU5OEjR3wBHxg8VTVZZV8X+Yvyzz/HLRsa+8KmKGoovSgNPTgx2oKHIiRzH9CmHr6CzgM6xStwp27uXQc1w7mnjflvqb5JXSpxawz8QXcvt9Q1lkLfXoD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, #"Country " = _t, #"City " = _t, #"Street " = _t, #"House " = _t, #"Unit " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Country ", type text}, {"City ", type text}, {"Street ", type text}, {"House ", type text}, {"Unit ", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] = "Null")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Attribute"}, {{"Count", each Table.RowCount(_), type number}}),
    #"Transposed Table" = Table.Transpose(#"Grouped Rows"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Street ", Int64.Type}, {"House ", Int64.Type}, {"Unit ", Int64.Type}, {"Country ", Int64.Type}, {"City ", Int64.Type}})
in
    #"Changed Type1"

  2.PNG

 

2. Append tables to get the excepted result.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZVAxDsIwEPsKurlD09DcZSwIBpBAoA5A1B907f+xQ1AqGHyxzr5zkpTESSMD8AC6DsWxE9ogU5OEjR3wBHxg8VTVZZV8X+Yvyzz/HLRsa+8KmKGoovSgNPTgx2oKHIiRzH9CmHr6CzgM6xStwp27uXQc1w7mnjflvqb5JXSpxawz8QXcvt9Q1lkLfXoD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, #"Country " = _t, #"City " = _t, #"Street " = _t, #"House " = _t, #"Unit " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Country ", type text}, {"City ", type text}, {"Street ", type text}, {"House ", type text}, {"Unit ", type text}}),
    #"Appended Query" = Table.Combine({#"Changed Type", #"Table (3)"})
in
    #"Appended Query"

Capture.PNG

 

 

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

Well done mate @Greg_Deckler  🙂

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

I know it's dumb but I was so pleased with myself! 🙂



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.