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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Rasmusrock
Helper II
Helper II

DAX help

 

Hi all,

 

I am looking for help with a DAX formula, and was hoping someone here could help me.


To set the context, i have data from two tables (purchasing lines and stock lines), and i want to make a table of how many unique creditors are active across the two tables.

 

So right now, i use the DISTINCTCOUNT formula on creditor number to get the unique creditors that are active in each table, however, the problem comes when a creditor is active in both tables, as shown below:

 

CountryKreditorer (indkøb)Kreditorer (lager)Antal aktive kreditorer
Danmark91322
Creditor 1112
Creditor 2112
Creditor 3 11
Creditor 4 11
Creditor 5112
Creditor 6112
Creditor 7112
Creditor 8112
Creditor 9 11
Creditor 10 11
Creditor 11112
Creditor 12112
Creditor 13112

 

So, the above table shows the active creditors for the country Denmark:

 

There are 13 unique creditors, all in all, 9 in the purchasing lines and 13 from the stock lines. However, when i add the two measures together, is says there are 22 unique creditors active, as some of them are active in both tables..

 

So can anyone help me with a formula that combines the two DISTINCT count formulas, but counts creditors that are active in both tables as one?

 

Home someone can help,

 

/Rasmus

1 ACCEPTED SOLUTION

 

Hi @Rasmusrock,

I try to reproduce your scenario using the following table.

Capture1.PNG2.png


You'd better merge the table into one new table using PowerQuery based on the Creditor ID. In the Power Query Editer window, click the Combine->Merge, you will get the snapshot below.

 
Capture2.PNG
Please click load&close, import the new table into model. Then create a calculated column using the formula in table.

=IF(Table2[Kreditorer(indk)]||Table2[NewColumn Kreditorer (lager)],1,0)

Capture3.PNG

Then you can count the active creditor based on the calculated coulmn as follows. 

Unigue ID:=CALCULATE(DISTINCTCOUNT(Table2[Creditor ID]),FILTER(Table2,Table2[New]=1))

Best Regards,
Angelia

View solution in original post

3 REPLIES 3
DataChant
Most Valuable Professional
Most Valuable Professional

Can you provide more information on the table schemas you use?

 

Assuming you have Table1 and Table2 with columns ID for the creditors IDs, this measure can count the unique IDs

Unique IDs = COUNTROWS ( DISTINCT ( UNION ( VALUES ( Table1[ID] ) , VALUES (Table2[ID] ) ) ) )

 

Thanks for your reply @DataChant.

 

I have two tables, each with a column showing the creditor ID.

 

I tried using your expression, however, as i am using Excel 2010, the 'UNION' function does not work. Is there a counterpart, or some kind of a workaround to this function in powerpivot 2010?

 

Best regards,

 

/Rasmus

 

Hi @Rasmusrock,

I try to reproduce your scenario using the following table.

Capture1.PNG2.png


You'd better merge the table into one new table using PowerQuery based on the Creditor ID. In the Power Query Editer window, click the Combine->Merge, you will get the snapshot below.

 
Capture2.PNG
Please click load&close, import the new table into model. Then create a calculated column using the formula in table.

=IF(Table2[Kreditorer(indk)]||Table2[NewColumn Kreditorer (lager)],1,0)

Capture3.PNG

Then you can count the active creditor based on the calculated coulmn as follows. 

Unigue ID:=CALCULATE(DISTINCTCOUNT(Table2[Creditor ID]),FILTER(Table2,Table2[New]=1))

Best Regards,
Angelia

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.