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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
h162672
New Member

Create Table where registers are measures from other table

Hello everyone

 

This is my case: I have a table and I need to know how many records I have by column.

 

Table Users from Database

codNameCountry
1HugoCO
2Paco 
3LuisPE

 

The new Table

cod

 TableColumnNameTotalRows
1Usersid3
2UsersName3
3UsersCountry2

 

Thanks for your help !!!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @h162672 ,

 

I suggest you to try this code.

Table 2 =
ADDCOLUMNS (
    VALUES ( 'Table'[cod] ),
    "Table Column Name", SWITCH ( [cod], 1, "Users id", 2, "Users Name", 3, "Users Country" ),
    "TotalRows",
        SWITCH (
            [cod],
            1, CALCULATE ( DISTINCTCOUNT ( 'Table'[cod] ), ALL ( 'Table' ) ),
            2, CALCULATE ( DISTINCTCOUNT ( 'Table'[Name] ), ALL ( 'Table' ) ),
            3,
                CALCULATE (
                    DISTINCTCOUNT ( 'Table'[Country] ),
                    FILTER ( ALL ( 'Table' ), 'Table'[Country] <> BLANK () )
                )
        )
)

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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
Anonymous
Not applicable

Hi @h162672 ,

 

I suggest you to try this code.

Table 2 =
ADDCOLUMNS (
    VALUES ( 'Table'[cod] ),
    "Table Column Name", SWITCH ( [cod], 1, "Users id", 2, "Users Name", 3, "Users Country" ),
    "TotalRows",
        SWITCH (
            [cod],
            1, CALCULATE ( DISTINCTCOUNT ( 'Table'[cod] ), ALL ( 'Table' ) ),
            2, CALCULATE ( DISTINCTCOUNT ( 'Table'[Name] ), ALL ( 'Table' ) ),
            3,
                CALCULATE (
                    DISTINCTCOUNT ( 'Table'[Country] ),
                    FILTER ( ALL ( 'Table' ), 'Table'[Country] <> BLANK () )
                )
        )
)

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

tamerj1
Super User
Super User

Hi @h162672 
The following calculated table shall provide the desired result

Users 1 = 
VAR IDs =
    SELECTCOLUMNS ( 
        { ( 1, "Users" , "id", COUNTROWS ( Users ) - COUNTBLANK ( Users[cod] ) ) },
         "cod", [Value1], "Table", [Value2], "ColumnName", [Value3], "TotalRows", [Value4] 
    )
VAR Names =
    SELECTCOLUMNS ( 
        { ( 2, "Users" , "Name", COUNTROWS ( Users ) - COUNTBLANK ( Users[Name] ) ) },
         "cod", [Value1], "Table", [Value2], "ColumnName", [Value3], "TotalRows", [Value4] 
    )
VAR Countries =
    SELECTCOLUMNS ( 
        { ( 3, "Users" , "Country", COUNTROWS ( Users ) - COUNTBLANK ( Users[Country] ) ) },
         "cod", [Value1], "Table", [Value2], "ColumnName", [Value3], "TotalRows", [Value4] 
    )
RETURN
    UNION ( IDs, Names, Countries )

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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