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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply

Difference (Items) between 2 tables

Hi, 

 

I have a requirement, where we have to find list of values from a columns that are not availalbe in a column in another table. To explain it better, I have a table which has the list of standard products: 

 

Base Product List 
 
Product Name 
Product A
Product B
Product C
Product D
Product E

 

There is another country level trasaction table which looks likes below: 

 

Transaction Table 
  
CountryProduct Name 
Country 1Product A
Country 1Product A
Country 1Product B
Country 1Product C
Country 1Product B
Country 1Product B
Country 1Product B
Country 1Product B
Country 1Product B
Country 2Product D
Country 2Product A
Country 2Product A
Country 2Product B
Country 2Product Z

 

Our requirment is that we have to find of list of products that are not available in transaction table for each country. Similarly we also have to find out if there is any product in the country table that is not available in the product table. Sample Output: 

 

Jagan_MFilterIT_0-1642764524256.png

 

This needs to be computed dynamically based on dates selected etc. 

 

Is there any way to do it ? 

 

 

1 ACCEPTED SOLUTION

Hi @Jagan_MFilterIT ,

 

Please create a new table:

 

Crossjoin Table = 
CROSSJOIN (
    VALUES ( 'Transaction Table'[Country] ),
    DISTINCT (
        UNION (
            VALUES ( 'Base Product List'[Product Name] ),
            VALUES ( 'Transaction Table'[Product Name] )
        )
    )
)

vkkfmsft_1-1643096661660.png

 

Then create measure and filter Measure = 1 for this visual.

Measure = 
var BaseTab = 
    CROSSJOIN (
        VALUES ( 'Transaction Table'[Country] ),
        VALUES ( 'Base Product List'[Product Name] )
    )
var TransTab = 
    GROUPBY ( 
        'Transaction Table',
        'Transaction Table'[Country],
        'Transaction Table'[Product Name]
    )
var InteresectRows = 
    DISTINCT ( 
        UNION ( EXCEPT ( BaseTab, TransTab ), EXCEPT ( TransTab, BaseTab ) )
    )
return COUNTROWS ( INTERSECT ( 'Crossjoin Table', InteresectRows ) )

vkkfmsft_0-1643096633663.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Jagan_MFilterIT , have separate country dimesion too. Then plot country from country and product from product and this measure

 

M1= countrows(Table) 

 

final measure =

Sumx(Addcolumns( summarize(Table, Product[Product], country[Country]) , "_1", if(isblank([M1]),1 ,blank()) ) , [_1])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi Sir, 

 

Thanks for the reply. I tried to recreate this but the final measure is only giving a blank value. I am not able to attach the sample Pbix file. 

 

Hi @Jagan_MFilterIT ,

 

Please create a new table:

 

Crossjoin Table = 
CROSSJOIN (
    VALUES ( 'Transaction Table'[Country] ),
    DISTINCT (
        UNION (
            VALUES ( 'Base Product List'[Product Name] ),
            VALUES ( 'Transaction Table'[Product Name] )
        )
    )
)

vkkfmsft_1-1643096661660.png

 

Then create measure and filter Measure = 1 for this visual.

Measure = 
var BaseTab = 
    CROSSJOIN (
        VALUES ( 'Transaction Table'[Country] ),
        VALUES ( 'Base Product List'[Product Name] )
    )
var TransTab = 
    GROUPBY ( 
        'Transaction Table',
        'Transaction Table'[Country],
        'Transaction Table'[Product Name]
    )
var InteresectRows = 
    DISTINCT ( 
        UNION ( EXCEPT ( BaseTab, TransTab ), EXCEPT ( TransTab, BaseTab ) )
    )
return COUNTROWS ( INTERSECT ( 'Crossjoin Table', InteresectRows ) )

vkkfmsft_0-1643096633663.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sir, Thanks a lot for this! This is exactly what I wanted. I am trying to now understand the logic better! Thanks Much! 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.