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
JulietZhu
Helper IV
Helper IV

DAX help from table join

Need translate those sql into DAX.

 SELECT COUNT(DISTINCT b.billId) AS BilledCount
  FROM Bill b WITH (NOLOCK)

LEFT JOIN dbo.Transactions t
      ON (b.Billid = t.billid)
WHERE t. TransactionTypeID= 4 and billdate between '2018-08-01' and '20180831'

 

I have two DAX. One is from Bill table, and the other one is from transction table. They have one to many relationship.

But both DAX give me different number from SQL statement. Can anyone help to see what is wrong with my DAX. Thanks.

 

1.PNG2.PNG

5 REPLIES 5
AkhilAshok
Solution Sage
Solution Sage

Why not try this way:

Billed Count =
CALCULATE (
    DISTINCTCOUNT ( Transactions[billId] ),
    Transactions[TransactionTypeID] = 4
)

The filter on TransactionTypeID won't flow to Bill table (since it is the one side of relationship). So, if you take distinctcount billID fron Bill table, then you have to either enable bi-directional filtering between Bill & Transactions, or use CROSSFILTER function in DAX. A more performing approach is to just take Distinctocunt of BillID from Transactions table as I showed.

v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @JulietZhu,

 

Can you share the relationship? It's better to have the file if possible.

1. How does "Date" table connect with other tables?

2. Are the relationships set to filter both? The "Cross Filter Direction" setting.

3. Are all the IDs in both tables?

I think the [Bill] shouldn't be filtered.

 

 

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.

Here is relationship.

 

Capture.PNG

Hi @JulietZhu,

 

@AkhilAshok just explained and gave the solution. Please try it out in your model.

 

 

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.

@v-jiascu-msft@AkhilAshok, the DAX I used actually is correct becuase when I only choose those 3 tables in my data modeling, both DAX I used are correct. Since there are other tables in data modeling, several ways can do calcuation. That is why whatever DAX are used, it won't give the correct answer.

 

The solution for this is that I write sql query in database and bring in another fact table in my data modeling. Thanks for helping.

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.