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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Count number of columns measure

Hi, 

 

is there any way to count the number of columns in a table? (to be displayed in a visual) 

I don't see a function that would do this as a measure. 

My other idea would be to transpose the table and count rows, but I don't see a function for that either.

 

Thanks,

Ruben

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

You can do it in PowerQuery.  If you reference your first query as the source you can keep only the first row then unpivot all the columns.  In my example I have a table called "data"

let
    Source = data,
    #"Kept First Rows" = Table.FirstN(Source,1),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Kept First Rows", {}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Just make sure to select all the columns before you unpivot.

TableCountColumns.jpg

Then you feed this to the model and do the count off the new table.  You could even remove the value column before loading it.

 

 

 

View solution in original post

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Try this:

1. In Power Query Editor, Duplicate your table.

countofcolumns.png

2. Select all columns and UnPivot.

countofcolumns2-1.png

countofcolumns2.png

3. Remove 'Value' column.

countofcolumns3.png

4. Remove duplicate rows.

countofcolumns4.png.jpg

5. Create a measure.

Count of Columns = COUNTROWS ( 'Table (2)' )

countofcolumns5.png

6. Hidden 'Table (2)'.

countofcolumns6.png

 

Best Regards,

Icey

 

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

jdbuchanan71
Super User
Super User

You can do it in PowerQuery.  If you reference your first query as the source you can keep only the first row then unpivot all the columns.  In my example I have a table called "data"

let
    Source = data,
    #"Kept First Rows" = Table.FirstN(Source,1),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Kept First Rows", {}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Just make sure to select all the columns before you unpivot.

TableCountColumns.jpg

Then you feed this to the model and do the count off the new table.  You could even remove the value column before loading it.

 

 

 

kentyler
Solution Sage
Solution Sage

You and use the COUNTROWS() function to count rows once you transpose your table





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

@kentyler 

How do I transpose the table?

 

Kindest regards,

Ruben

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.