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
Anonymous
Not applicable

Comparing two excel sheets without merging

Hello,

 

I'm dealing with two warehouses that use different systems for item tracking. I receive weekly reports from each warehouse, and I just need to set up a dashboard that shows the differences. My current measure below partially works, it shows which items are missing, but I need to show the total quantity as well. One of the common columns in both sheets is the item ID, however whereas the sending warehouse records (almost) each item on a separate line, receiving warehouse records them in one line, adding a separate quantity column. To check whether one item is contained in the other I created this measure:

 

 

Contained in Table 2 = IF(
CONTAINS(
      'Receiving', 
      'Receiving'[ItemID], MAX('Sending'[ItemID)),
1,
0)

 

 

I created a "Quantity" column in the sending table and added "1" to each line. While this above measure shows me which items are not present in the receiving warehouse, it fails to show the number of items and as soon as I add the Quantity column from the receiving table, the visualization breaks. I actually only figured out my mistake when I compared the total numbers and what the measure shows me (54 in my viz, which is clearly wrong, see below).

 

thatakke_0-1628674601539.png

 

I can't merge/append these two tables for various reasons. Is there a way of creating a better measure that shows the differences in both tables as well as total number of items that do not appear in each tables? Any other suggestions?

 

Below are two example tables:

 

Sending

 

ItemIDDescriptionItem TypeQuantity (Custom Created)QTY (Some special items have a quantity line)
6570PowerBi DesktopSoftware1 
6570PowerBi DesktopSoftware1 
6575MS OfficeSoftware1 
6890ChairOffice Tools 1

 

Receiving

 

ItemIDDescriptionItem TypeQuantity
6570PowerBi DesktopSoftware2
6575MS OfficeSofware1
1 ACCEPTED SOLUTION

You have to filter out the rows containing "in transit":

try:

Table differences =
VAR receiving1 =
    SUMMARIZE (
        Receiving,
        Receiving[ItemID],
        Receiving[Description],
        Receiving[Item Type],
        "QT", SUM ( Receiving[Quantity])
    )
VAR sending1 =
    SUMMARIZE (
        FILTER(
        Sending, Sending[Status] <> "In transit"),
        Sending[ItemID],
        Sending[Description],
        Sending[Item Type],
        "QT", SUM ( Sending[Quantity (all)] )
    )
VAR OnlyRec =
    ADDCOLUMNS ( EXCEPT ( receiving1, sending1 ), "From table", "Receiving" )
VAR OnlySend =
    ADDCOLUMNS ( EXCEPT ( sending1, receiving1 ), "From table", "Sending" )
RETURN
    UNION ( OnlyRec, OnlySend )




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

8 REPLIES 8
PaulDBrown
Community Champion
Community Champion

You could create a new table to identify the rows which are not in the other table using something along the lines of:

 

Table differences =
VAR receiving1 =
    SELECTCOLUMNS (
        Receiving,
        "ItemID", Receiving[ItemID],
        "Description", Receiving[Description],
        "Item Type", Receiving[Item Type],
        "QT", Receiving[Quantity]
    )
VAR sending1 =
    SUMMARIZE (
        Sending,
        Sending[ItemID],
        Sending[Description],
        Sending[Item Type],
        "QT", SUM ( Sending[Quantity (all)] )
    )
VAR OnlyRec =
    ADDCOLUMNS ( EXCEPT ( receiving1, sending1 ), "From table", "Receiving" )
VAR OnlySend =
    ADDCOLUMNS ( EXCEPT ( sending1, receiving1 ), "From table", "Sending" )
RETURN
    UNION ( OnlyRec, OnlySend )

 

 

Which will get you this:

result.PNG

 

I've attached the sample PBIX file for your reference





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Thanks @PaulDBrown 


This is truly impressive. You've really shown your expertise on PBI. 

 

However, in my test, I found if in the receiving table they recorded 1 item per 1 line (they have done that sometimes), the difference table considers this as only 1 in quantity. See below, the item actually appears in 7 different lines in the receiving table, so technically it shouldn't appear on this table at all (There are 7 items with the ID 6908 in both tables).

 

thatakke_0-1628691318510.png

When I show the QT column as a sum, the table shows the correct number, but this item shouldn't be here at all. See below:

 

thatakke_1-1628691756892.png

 

Any suggestions?

 

Thanks, 

In that case you need the SUMMARIZE function in the first VAR too.

 

 

Table differences =
VAR receiving1 =
    SUMMARIZE (
        Receiving,
        Receiving[ItemID],
        Receiving[Description],
        Receiving[Item Type],
        "QT", SUM ( Receiving[Quantity])
    )
VAR sending1 =
    SUMMARIZE (
        Sending,
        Sending[ItemID],
        Sending[Description],
        Sending[Item Type],
        "QT", SUM ( Sending[Quantity (all)] )
    )
VAR OnlyRec =
    ADDCOLUMNS ( EXCEPT ( receiving1, sending1 ), "From table", "Receiving" )
VAR OnlySend =
    ADDCOLUMNS ( EXCEPT ( sending1, receiving1 ), "From table", "Sending" )
RETURN
    UNION ( OnlyRec, OnlySend )

 

 

try that and see if it works.

 

BTW, since this is table, you can create measures for example to calculate the balance by row as a summary





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Amazing! Thanks @PaulDBrown 

One final question, in my sending table I have a "Status" column that shows the item's current status. Do you have a recommendation for me to integrate it to this table differences, so it ignores items that has the status "In transit"?

Thanks, 

You have to filter out the rows containing "in transit":

try:

Table differences =
VAR receiving1 =
    SUMMARIZE (
        Receiving,
        Receiving[ItemID],
        Receiving[Description],
        Receiving[Item Type],
        "QT", SUM ( Receiving[Quantity])
    )
VAR sending1 =
    SUMMARIZE (
        FILTER(
        Sending, Sending[Status] <> "In transit"),
        Sending[ItemID],
        Sending[Description],
        Sending[Item Type],
        "QT", SUM ( Sending[Quantity (all)] )
    )
VAR OnlyRec =
    ADDCOLUMNS ( EXCEPT ( receiving1, sending1 ), "From table", "Receiving" )
VAR OnlySend =
    ADDCOLUMNS ( EXCEPT ( sending1, receiving1 ), "From table", "Sending" )
RETURN
    UNION ( OnlyRec, OnlySend )




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Awesome! Thanks @PaulDBrown It works marvelously! 


I hate to be that guy, but do you have a more elegant solution than what I have, regarding the differences per item? I created 3 measures and used a matrix viz to show difference per item, so it shows 1 and -1 for the below two rows:

 

thatakke_0-1629275194385.png

Here are the measures: 

Sum Sending = CALCULATE(SUM('Table differences'[Quantity]), 'Table differences'[Source] = "Sending")

Sum Receiving= CALCULATE(SUM('Table differences'[Quantity]), 'Table differences'[Source] = "Receiving")

Sum Differnece = [Sum Sending] - [Sum Receiving]

 

Obviously when I do that, I get an annoyingly ugly result:

 

thatakke_1-1629277528835.png

 

If you have a better solution, I would be happy to learn.

Thanks,

I take it the "QT" are columns from the table. If you are using a matrix, use measures instead (leave the column bucket empty),  or try a table visual instead of a matrix.
You can also "hide" a column in a visual by dragging the boundary, but you need to turn off word-wrap and maybe auto-width in the formatting pane.





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

You're a savior! Many thanks!

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.