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
vishwa_sg
New Member

DAX to calculate dynamically within Selected Group

Dear Community,

 

I am very new to power BI. This could be simple requirement but I am struggling to make it work. 

 

Here is my requirement :

DAX to calculate dynamically within group. 

TypeEMPLIDCalculationexpected result
CTA1001distinct emplid/ count(type)0.33
Generic1001distinct emplid/ count(type)0.33
Email1001distinct emplid/ count(type)0.33
XYZ1002distinct emplid/ count(type)1.00

 

I have Type slicer on the report page and when I select ex: Type ->CTA, Generic then expected result is 

 

TypeEMPLIDCalculationexpected result
CTA1001distinct emplid/ count(type)0.50
Generic1001distinct emplid/ count(type)0.50
Email1001distinct emplid/ count(type) 
XYZ1002distinct emplid/ count(type) 

 

Please help.

 

Thanks,

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@vishwa_sg 

measure = divide(distinctcount(emplid), calculate(distinctcount(type), allselected(type)))

@vishwa_sg Here is a link to download a sample solution file:

DAX to calculate dynamically within Selected Group 2022-08-10.pbix


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Showcase Report – Contoso By SpartaBI

Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

View solution in original post

3 REPLIES 3
vishwa_sg
New Member

Hi @SpartaBI  Thank you so much. 

 

By using your formula. I managed to achieve the expected result. Have to calculate within a group and here is the working DAX

 

Oppty Engaged = SUMX(SUMMARIZE(Contact,Contact[Id] , "res", divide(distinctcount('Fact Oppty Engaged'[OptyID]), calculate(distinctcount('Fact Campaign Member'[CampaignType]), allselected('Fact Campaign Member'[CampaignType])))),[res])

@my pleasure 🙂
P.S. Check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas. Please give it a thumbs up over there if you liked it 🙂https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543

SpartaBI
Community Champion
Community Champion

@vishwa_sg 

measure = divide(distinctcount(emplid), calculate(distinctcount(type), allselected(type)))

@vishwa_sg Here is a link to download a sample solution file:

DAX to calculate dynamically within Selected Group 2022-08-10.pbix


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Showcase Report – Contoso By SpartaBI

Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

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.

Top Solution Authors