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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.