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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
clarkey1988
Helper II
Helper II

Distinct Count Multiple Columns across two tables

Hi,

 

I have a calculated column in Table 1 (TARDbQuery) that sums the total miles for an order number from Table 2 "Trip Detail" based off the month and year in Table 1.

 

So I have a total of 6,190 miles for an order number in January 2020.

 

I now need to divide this by the disincty count of order numbers in Table 2 using the same parameters as above.

 

TMW Master Miles = SUMX(FILTER('Trip Detail','Trip Detail'[RouteNumber]=TARDbQuery[Route]&&'Trip Detail'[Month]=TARDbQuery[Month]&&'Trip Detail'[Year]=TARDbQuery[Year]),'Trip Detail'[Miles])
 
 

 

 

Please could someone help me?

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @clarkey1988 

 

Which parameters do "the same parameters as above" refer to? If they are Month and Year, you could try below codes to add a calculated column in Table 1.

 

Column = DIVIDE('Table1'[TMW Master Miles],CALCULATE(DISTINCTCOUNT('Table2'[RouteNumber]),FILTER('Table2','Table2'[Month]='Table1'[Month]&&'Table2'[Year]='Table1'[Year])))

 

012501.jpg

If they are RouteNumber, Month and Year, I think the distinct count is always 1 (assume that Route Number is order number)? 

 

If I don't understand it correctly, can you share some sample data and expected result without sensitive info so we can work with it further?

 

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @clarkey1988 

 

Which parameters do "the same parameters as above" refer to? If they are Month and Year, you could try below codes to add a calculated column in Table 1.

 

Column = DIVIDE('Table1'[TMW Master Miles],CALCULATE(DISTINCTCOUNT('Table2'[RouteNumber]),FILTER('Table2','Table2'[Month]='Table1'[Month]&&'Table2'[Year]='Table1'[Year])))

 

012501.jpg

If they are RouteNumber, Month and Year, I think the distinct count is always 1 (assume that Route Number is order number)? 

 

If I don't understand it correctly, can you share some sample data and expected result without sensitive info so we can work with it further?

 

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

clarkey1988
Helper II
Helper II

clarkey1988_0-1611239545205.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.