Forum Discussion

LeHello's avatar
LeHello
Copper Contributor
Apr 15, 2025

Union and then distinct values of a column

Hi, 
Here is a description of my problem. 

I have 3 tables, but i will take the example of 2. in each table, I have a column "common_col". I want to combine the values of this 2 tables to get one column and then return the distinct values : like that i will be sure that i have the values of each tables. 

********************Script 1**********************

((table1
| project common_col
| distinct common_col)

 

| union

(table2
| project common_col
| distinct common_col))


| distinct common_col

*******************************************************

******************Script 2 ********************************

((table1
| project common_col
| distinct common_col)

 

| union

(mv_pdb_process_stl
| project common_col
| distinct common_col))


| summarize by common_col

**********************************************************

The first and second script, because when after importing the data in Power BI, I tried this :

Nb_distinct_values = DISTINCTCOUNT('Newtable'[common_col])

Nb_Total_rows = COUNTROWS('common_col')

 

I don't get the same number and it is don't normal. So there is an issue in my script and I need help please ! Thanks ! 

1 Reply

  • petevern's avatar
    petevern
    Copper Contributor

    Can you try to not apply distinct before the union?

    Like this:

    table1
    | project common_col
    | union (table2 | project common_col)
    | summarize by common_col //or distinct common_col

Resources