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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Measure with Sum and group by, and use this measure in slicer

Hi Experts,

 

I have a requirement where I need to find the patients who have thier total dispense days greater than certain days (adjustable using slicer) for a particular drug.

I have attached sample pbix file to help. 

https://drive.google.com/file/d/1AC_mi1FB_fc0-L24G9-zoTU0kzGj0loK/view?usp=sharing

 

 

I would have two slicers in the report, one for the dispense date and the other on the total number of dispense days.

 

I am looking at having a measure that sums the dispense days grouped by the patient and the drug and then use this as the one of the slicer above.

 

Appreciate your help here.

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The below code met my requirement.

 

Measure 5 = CALCULATE(SUM(DispenseTable[Drug Dispensed Days]), FILTER(ALLSELECTED(DispenseTable),DispenseTable[PatientId] = Max(DispenseTable[PatientId])),FILTER(ALLSELECTED(DrugTable),DrugTable[MP] = Max(DrugTable[MP])))

 

 

https://drive.google.com/file/d/1AC_mi1FB_fc0-L24G9-zoTU0kzGj0loK/view?usp=sharing

 

 

The solution in the below post helped me:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Group-by-in-the-measure/m-p/2160496

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

The below code met my requirement.

 

Measure 5 = CALCULATE(SUM(DispenseTable[Drug Dispensed Days]), FILTER(ALLSELECTED(DispenseTable),DispenseTable[PatientId] = Max(DispenseTable[PatientId])),FILTER(ALLSELECTED(DrugTable),DrugTable[MP] = Max(DrugTable[MP])))

 

 

https://drive.google.com/file/d/1AC_mi1FB_fc0-L24G9-zoTU0kzGj0loK/view?usp=sharing

 

 

The solution in the below post helped me:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Group-by-in-the-measure/m-p/2160496

 

Anonymous
Not applicable

Thanks @amitchandak .

 

Would something similar to the solution in the below would work?

https://community.powerbi.com/t5/Desktop/DAX-SUM-with-GROUP-BY/m-p/703429

 

Please find updated pbix file in the link that I am trying to work but I don't get the same results as in the above solution.

 

My pbix: https://drive.google.com/file/d/1AC_mi1FB_fc0-L24G9-zoTU0kzGj0loK/view?usp=sharing

 

amitchandak
Super User
Super User

@Anonymous , Seem like you are looking for Dynamic segmentation -Measure to Dimension conversion: https://youtu.be/gzY40NWJpWQ

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors