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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SS-PBI
Frequent Visitor

Help: DistinctCount by DistinctCount

Good Morning,

I am trying to get the distinctcount of a column by the distinct count of another. 

I have a table with 3 columns, Date, Volunteer, and Location.

I need to calculate the percent of volunteers working by the count of distinct locations they volunteered at, as shown in the image below, the table visual on the right. I use a slider to select the date ranges. So far, I am having difficulty in Power BI to get this working correctly.

 
 

Screenshot 2020-11-13 134010.png

 

The table on the right is based on a SUMMARIZE function to create a new table that has Volunteer and Count of Location (distinct count of locations volunteered at), and then I can create a measure with the total number of distinct volunteers and another measure with the distinct count of volunteers. A third measure is used to calculate the percentage.

My problem is the SUMMARIZE function doesn't take the date slider into account. How do I go about doing this best in Power BI?

My file is here:

https://algonquinlivecom-my.sharepoint.com/:u:/g/personal/robinss_algonquincollege_com/EcesszcFjeVHk... 

 

UPDATE: Changed link to OneDrive location

@v-yiruan-msft 

 

 

 

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

Hi @SS-PBI ,

Sorry for delay... You can follow the below steps to achieve it, please find the details in Page 2 of attachment:

1. Create a calculated table Location number

Location number = GENERATESERIES(1,DISTINCTCOUNT('Volunteer Data'[Location]),1)

2. Create a measure to get the number of volunteer per location number group

Count of Volunteers = 
VAR _tab =
    SUMMARIZE (
        'Volunteer Data',
        'Volunteer Data'[Volunteer],
        "countofL", CALCULATE ( COUNT ( 'Volunteer Data'[Location] ) )
    )
VAR _tab2 =
    FILTER (
        CROSSJOIN ( 'Location number', _tab ),
        [countofL] = 'Location number'[Number]
    )
RETURN
    COUNTAX ( _tab2, [Volunteer] )

3. Update the formula of measure [Percent Volunteers]: replace measure [Count of Volunteers 2] with new created measure [Count of Volunteers]

Percent Volunteers = [Count of Volunteers] / [Total Unique Volunteers]

DistinctCount by DistinctCount.png

Best Regards

Community Support Team _ Rena
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
v-yiruan-msft
Community Support
Community Support

Hi @SS-PBI ,

Sorry for delay... You can follow the below steps to achieve it, please find the details in Page 2 of attachment:

1. Create a calculated table Location number

Location number = GENERATESERIES(1,DISTINCTCOUNT('Volunteer Data'[Location]),1)

2. Create a measure to get the number of volunteer per location number group

Count of Volunteers = 
VAR _tab =
    SUMMARIZE (
        'Volunteer Data',
        'Volunteer Data'[Volunteer],
        "countofL", CALCULATE ( COUNT ( 'Volunteer Data'[Location] ) )
    )
VAR _tab2 =
    FILTER (
        CROSSJOIN ( 'Location number', _tab ),
        [countofL] = 'Location number'[Number]
    )
RETURN
    COUNTAX ( _tab2, [Volunteer] )

3. Update the formula of measure [Percent Volunteers]: replace measure [Count of Volunteers 2] with new created measure [Count of Volunteers]

Percent Volunteers = [Count of Volunteers] / [Total Unique Volunteers]

DistinctCount by DistinctCount.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

Hi @SS-PBI  ,

I'm sorry that I have no access to your file. Could you please upload your file to OneDrive for Business, then share the file link with me. Please find the details in the following documentation.

Share OneDrive files and folders

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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