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
lgs1983
Helper I
Helper I

Distinct Count with grouping for calculated column

Hi All,

 

I've tried to search the answer to my question but have failed on the numerous paths I've followed so am hoping you are able to help.

 

I have the following columns and what I want to do is create a calculated column to provide a distinct count where for A where, B is different, so:

 

Column1   Mapping       COUNT

A                AA1               2

A                AA1               2

A                AA2               2

B                AA1               2

B                AA2               2

C                AA1               1

C                AA1               1

C                AA1               1

 

So hopefully this makes sense, for A there are two distinct different mappings provided, the same for B. For C though there is only one distinct mapping provided

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Try using this for Calculated column:

Count Column = 
VAR v_SeriesCnt = CALCULATE
( 
    DISTINCTCOUNT( Data[Mapping] ), 
    ALLEXCEPT( Data, Data[Column1] ) 
 )
 RETURN
 v_SeriesCnt

Thanks.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Try using this for Calculated column:

Count Column = 
VAR v_SeriesCnt = CALCULATE
( 
    DISTINCTCOUNT( Data[Mapping] ), 
    ALLEXCEPT( Data, Data[Column1] ) 
 )
 RETURN
 v_SeriesCnt

Thanks.

@Anonymous Wow, that work just as I wanted.

 

I'm sure it's going to be over my head but what does the VAR v_SeriesCnt do? I'm assuming v_SeriesCnt is the name of the variable.

Anonymous
Not applicable

That's correct. It is just a variable.

Why does the formula have to be inside the variable? What's it's impact?

Anonymous
Not applicable

It does not have to be inside a variable. You can write it without variable too.

Count Column =
CALCULATE
( 
    DISTINCTCOUNT( Data[Mapping] ), 
    ALLEXCEPT( Data, Data[Column1] ) 
 )

Thanks.

Cool.

 

So I'm going to try to explain this formula, please correct me (if you want to that is) where I've gone astray. 

 

So the ALLEXCEPT is used as a filter where in theory it only looks at Column 1 and rest of the formula looks at the distinct mappings for those?

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.