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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
carted01
Frequent Visitor

Count Distinct Rows of Dimension Table using multiple fact tables

Hi,

 

I need a measure to count the distinct number of active accounts in any given time period. This has been easy in the past where I have only had one table for sales data. However with this new model, there are 4 seperate sales tables. Each has a relationship to the "Debtors" table with a unique key for each sales table (eg [ACCNO] for Direct sales, [Customer ID (ALM)]  for ALM).

 

In the below table, I have made a measure for each seperate sales table, with a distinct count of account numbers within each. EG:

Distributions (ALM) = distinctcount('Sales Data (ALM)'[Customer ID (ALM)]),
 
This works fine when only looking at one sales source, but i wish to count the unique number of accounts across all 4
 
Adding the 4 measures together as is doesn't work, as it creates double ups if an account has purchased from more than one source, and the below test measure has a simlar effect.
 
Test = COUNTROWS(
    DISTINCT(
        UNION(
            VALUES( 'Sales Data (Direct)'[ACCNO]),
            VALUES( 'Sales Data (ALM)'[Customer ID (ALM)] ),
            VALUES( 'Sales Data (LMX)'[Cust. No] ),
            VALUES( 'Sales Data (Paramount)'[Company])
        )))
 
Can anyone help?
In the below the answer I am after is 38, however I just can't seem to get there.
 
Debtor Table [ACCNO]Distributions (Direct)Distributions (ALM)Distributions (LMX)Distributions (Paramount)DistributionsTest
141   11
371   11
671   11
3761   11
534 1  11
5801   11
63111  12
6461 1 12
6511   11
6521   11
653  1 11
6581   11
6631 1 12
719 1  11
752  1 11
795  1 11
7961   11
930 1  11
934  1 11
984 1  11
1025   111
10581   11
1227  1 11
12991   11
1658 1  11
1757 1  11
18231   11
19751   11
21861 1 12
21871   11
22361   11
22611   11
27041   11
27481   11
2871  1 11
34031   11
3429  1 11
3746  1 11
38    142
 

 

1 REPLY 1
some_bih
Super User
Super User

Hi @carted01 uz Power Query to do UNION query and then remove duplicate keys, after that use measure to countrows (before this backup your work :)). I hope this help.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.