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
jostnachs
Helper III
Helper III

Calculated column groupby

 

Hi All... I have a requirement where i have to add column in one of the tables where i have to find the count of prbrnames grouped for each policy id. Policyid is in policy table and Prbrnames are in producer broker table. the relation between two tables is through a common table called production. I am using the below formula

PolicyShareStatus1 =

VAR c = CALCULATE ( COUNT ( 'Producer Broker'[PrBrName] ), ALLEXCEPT ( 'Policy', Policy[_PolicyID] ) )

RETURN

C

But the result is not as expected. If you see below the table the same policy number having multiple prbrnames has to have number 3 instead of 1

jostnachs_0-1728052697607.png

 

jostnachs_1-1728052697609.png

 

1 ACCEPTED SOLUTION
v-yohua-msft
Community Support
Community Support

Hi, @jostnachs 

Based on your information, I create sample tables:

Policy Table

vyohuamsft_0-1728266688533.png

Producer Broker Table

vyohuamsft_1-1728266709859.png

Production Table

vyohuamsft_2-1728266757617.png

 

Then create a new calculated column, try the following DAX expression:

PolicyShareStatus1 = 
CALCULATE (
    COUNT ( 'Producer Broker'[PrBrName] ),
    FILTER (
        ALL ( 'Producer Broker' ),
        'Producer Broker'[PolicyID] = EARLIER ( 'Policy'[PolicyID])
    )
)

 

Here is my preview:

vyohuamsft_3-1728266823730.png

vyohuamsft_4-1728266834778.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

4 REPLIES 4
v-yohua-msft
Community Support
Community Support

Hi, @jostnachs 

Based on your information, I create sample tables:

Policy Table

vyohuamsft_0-1728266688533.png

Producer Broker Table

vyohuamsft_1-1728266709859.png

Production Table

vyohuamsft_2-1728266757617.png

 

Then create a new calculated column, try the following DAX expression:

PolicyShareStatus1 = 
CALCULATE (
    COUNT ( 'Producer Broker'[PrBrName] ),
    FILTER (
        ALL ( 'Producer Broker' ),
        'Producer Broker'[PolicyID] = EARLIER ( 'Policy'[PolicyID])
    )
)

 

Here is my preview:

vyohuamsft_3-1728266823730.png

vyohuamsft_4-1728266834778.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

dharmendars007
Memorable Member
Memorable Member

Hello @jostnachs , 

 

Can you please try with Disticntcount logic like the below..

 

PolicyShareStatus1 =
CALCULATE(DISTINCTCOUNT('Producer Broker'[PrBrName]),

                     ALLEXCEPT('Policy', 'Policy'[PolicyID]))

 

If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!

 

Thank You

Dharmendar S

LinkedIN 

Still no luck....gives me the same result as it gave me previously

jostnachs_0-1728055111947.png

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information. Do not include anything that is unrelated to the issue or question.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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!

November Carousel

Fabric Community Update - November 2024

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

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.