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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
dennis_yin
Frequent Visitor

Simple SQL to DAX

I need help translating this query to DAX:

 

select sum(true_total) as physician_values, p.physician_id
from orders as o inner join prescriptions as p
on cast(o.purchased_on as date) <= p.script_end and cast(o.purchased_on as date) >= p.script_start and o.client_id = p.client_id
group by p.physician_id;

 

I tried using DirectQuery but I was having trouble slicing the data by date.

3 REPLIES 3
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @dennis_yin,

 

The measure could be like below. If you need a more precise solution, please provide a dummy sample. 

The o.client_id = p.client_id part will be achieved by the relationship.

Measure =
CALCULATE (
    SUM ( orders[true_total] ),
    FILTER (
        orders,
        orders[purchased_on] <= MIN ( prescriptions[script_end] )
            && orders[purchased_on] >= MIN ( prescriptions[script_start] )
    )
)

Best Regards,

Dale

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

Thanks for the reply Dale, but I realize now that I didn't properly explain what I'm trying to do. I need the sum of orders[true_total] for each unique physician, and I need to be able to filter valid prescriptions by a given date. So then if a user chooses September 1 with the date slicer, the true_total value for each physician only reflects prescriptions with a start date <= September 1, and an expiry date >= September 1.

Hi @dennis_yin,

 

Please share a dummy sample.

 

Best Regards,

Dale

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.