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
Hell-1931
Helper II
Helper II

How to add INNER JOIN but in DAX to an existing Measure?

Hello,

I have the following measure:

 

VAR countClients =
    CALCULATE (
        DISTINCTCOUNT ( 'C_Services'[ClientID] ),
        FILTER (
            'C_Services',
                   [ClientID] > 0
                && [Is Non-Claimable] = FALSE ()
                && [Is No-show] = FALSE ()
                && [Is Cancellation] = FALSE ()
        )
    )
RETURN
    countClients

 

 

which was translated from the following T-SQL:

 

SELECT 
	 cs.[ProgramName] AS [Program]
	,COUNT(DISTINCT cs.[ClientID]) AS [# Clients Served]
FROM 
	[C_Services] cs
WHERE
	    (cs.[ClientID] > 0)
	AND (cs.[IsNoShow] = 0) 
	AND (cs.[IsCancellation] = 0)
	AND (cs.[IsNonClaimable] = 0)

GROUP BY
	 cs.[ProgramName]

 

But the INNER JOIN was added to SQL:

 

FROM 
	[C_Services] cs
	INNER JOIN [C_Episodes] epi ON (
		    (epi.[ProgramID] = cs.[ProgramID])
		AND (epi.[ClientID] = cs.[ClientID])
		AND (epi.[AdmissionDate] <= cs.[ServiceMonth])
		AND (epi.[DischargeDate] >= cs.[ServiceMonth]) )

                                            

 

 

How do I write this new " INNER JOIN " addition in DAX?

 

I was trying the following to join on the 1st column [ProgramID] :

 

NATURALINNERJOIN('C_Services'[ProgramID], 'C_Episodes'[ProgramID])

 

 But it gives an error "grupping needed"; was trying to modify Calculate statement also, but no success...

 

Please, HELP!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Hell-1931 ,

First, you need to create relationships between C_Services and C_Episodes tables base on the field ProgramID and ClientID just as shown in below screenshot.

yingyinr_0-1625479669029.png

Then create a measure as below:

Measure = 
VAR _addate =
    CALCULATE (
        MAX ( 'C_Episodes'[AdmissionDate] ),
        USERELATIONSHIP ( 'C_Episodes'[ClientID], 'C_Services'[ClientID] )
    )
VAR _dsdate =
    CALCULATE (
        MAX ( 'C_Episodes'[DischargeDate] ),
        USERELATIONSHIP ( 'C_Episodes'[ClientID], 'C_Services'[ClientID] )
    )
VAR countClients =
    CALCULATE (
        DISTINCTCOUNT ( 'C_Services'[ClientID] ),
        USERELATIONSHIP ( 'C_Episodes'[ClientID], 'C_Services'[ClientID] ),
        FILTER (
            'C_Services',
            'C_Services'[ClientID] > 0
                && 'C_Services'[Is Non-Claimable] = 0
                && 'C_Services'[Is No-show] = 0
                && 'C_Services'[Is Cancellation] = 0
                && 'C_Services'[ServiceMonth] >= _addate
                && 'C_Services'[ServiceMonth] <= _dsdate
        )
    )
RETURN
    countClients

yingyinr_1-1625479723516.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Hell-1931 ,

First, you need to create relationships between C_Services and C_Episodes tables base on the field ProgramID and ClientID just as shown in below screenshot.

yingyinr_0-1625479669029.png

Then create a measure as below:

Measure = 
VAR _addate =
    CALCULATE (
        MAX ( 'C_Episodes'[AdmissionDate] ),
        USERELATIONSHIP ( 'C_Episodes'[ClientID], 'C_Services'[ClientID] )
    )
VAR _dsdate =
    CALCULATE (
        MAX ( 'C_Episodes'[DischargeDate] ),
        USERELATIONSHIP ( 'C_Episodes'[ClientID], 'C_Services'[ClientID] )
    )
VAR countClients =
    CALCULATE (
        DISTINCTCOUNT ( 'C_Services'[ClientID] ),
        USERELATIONSHIP ( 'C_Episodes'[ClientID], 'C_Services'[ClientID] ),
        FILTER (
            'C_Services',
            'C_Services'[ClientID] > 0
                && 'C_Services'[Is Non-Claimable] = 0
                && 'C_Services'[Is No-show] = 0
                && 'C_Services'[Is Cancellation] = 0
                && 'C_Services'[ServiceMonth] >= _addate
                && 'C_Services'[ServiceMonth] <= _dsdate
        )
    )
RETURN
    countClients

yingyinr_1-1625479723516.png

Best Regards

CNENFRNL
Community Champion
Community Champion

I don't think it's necessary to deploy INNER JOIN to DAX on purpose as filtering along with 1:* relationship is an instrinsic behavior in DAX. That's to say, once a relationship is created between C_Services[ProgramID] and C_Episodes[ProgramID], it constitute naturally an inner join. 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
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!

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.