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

Distinctcount GroupBy?

Hi, 

 

 

I have a table lets call it Facts it has the following coulmns: 

 

ProjectName         Dep        WorkerCode

X1                         Sales           89

X1                         Sales           63

X1                         Admin         77

X1                         Admin         99

X2                         Purshase     01

 

 

I want a measure, a table, or a column where i can count total numer of workers groubed by Department and Project name, so the result is something like

 

ProjectName        Dep          Tot. NrOfWorkers

X1                         Sales              2

X1                         Admin            2

X2                         purshase        1

 

I have tried the following but they are not working as I wished them to:

 

Column = CALCULATE(DISTINCTCOUNT(Facts[WorkerCode]),ALLEXCEPT(Facts,Facts[ProjectName],Facts[Dep]))

But its giving the right result

 

I have also tried to create a table from modeling:

 

Column = SUMMARIZE(Facts,Facts[ProjectName],Facts[Dep],"distinc",DISTINCTCOUNT(Facts[WorkerCode]))
 
 
But am getting an error saying the the expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
 
 
Your help is highly apprecitaed 🙂 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

or if you want the DAX version:

Table = 
ADDCOLUMNS(
    SUMMARIZECOLUMNS( 
        'Fact'[ProjectName ], 
        'Fact'[Dep      ]
    ),
    "Distinct Count", 
    CALCULATE(
        DISTINCTCOUNT('Fact'[WorkerCode])
    )
)

DAX table.png

View solution in original post

MarkLaf
Solution Sage
Solution Sage

I'll quickly note that if you're goal is to simply have a visual that shows this info in a report/dashboard, then you don't need to write any DAX.

 

Simply create a table visual, add in ProjectName, Dep, and WorkerCode, then hit dropdown on WorkerCode value and change aggregation setting to "Count (Distinct)" – you can change display name of the columns in the same dropdown menu, too (if for example you don't like "Count of WorkerCode").

 

Capture20190227.PNG

View solution in original post

7 REPLIES 7
v-jiascu-msft
Employee
Employee

Hi @Anonymous ,

 

Could you please mark the proper answers as solutions?

 

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MarkLaf
Solution Sage
Solution Sage

I'll quickly note that if you're goal is to simply have a visual that shows this info in a report/dashboard, then you don't need to write any DAX.

 

Simply create a table visual, add in ProjectName, Dep, and WorkerCode, then hit dropdown on WorkerCode value and change aggregation setting to "Count (Distinct)" – you can change display name of the columns in the same dropdown menu, too (if for example you don't like "Count of WorkerCode").

 

Capture20190227.PNG

Anonymous
Not applicable

if you are not oppose to using Power Query, this can be done with just a few clicks:

 

  1. Have your table loaded
  2. Reference that query (this will create a new query)
    1. Go to Transform--> Table--> GroupBy 
    2. Then use these inputs:
    3. Groupby Inputs.png
  3. And your final table:
  4. Final Table.png

 

 

Anonymous
Not applicable

or if you want the DAX version:

Table = 
ADDCOLUMNS(
    SUMMARIZECOLUMNS( 
        'Fact'[ProjectName ], 
        'Fact'[Dep      ]
    ),
    "Distinct Count", 
    CALCULATE(
        DISTINCTCOUNT('Fact'[WorkerCode])
    )
)

DAX table.png

Anonymous
Not applicable

It worked in my case.. many thanks for that. 🙂 

Anonymous
Not applicable

Many thanks for your answer. However, Iam still getting the following when using DAX: "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value"

 

Any suggestions? 

Anonymous
Not applicable

Be sure you are using New Table, and not New Measure or New Column

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.