Forum Discussion
Compare two excel files in PowerBI
- 5 years ago
Here is one way. (Apologies since I worked on a sample dataset)
1) Create two disconnected tables to use as slicers with the unique values for the file names. Here is what my model looks like:
2) add a column ("String" in the my example) which concatenates the values of each column in the table containg the appended rows from all the tables3) Create a measure to use in the filter pane for slicer 2. This filter will filter out the values we select on slicer 1 from slicer 2:
Filter Slicer 2 = COUNTROWS(EXCEPT('File Slicer 2', 'File Slicer 1'))3) Create a measure to return the rows which are not present in both tables
Different Rows = VAR Table1 = CALCULATETABLE(VALUES('Full Table'[String]), FILTER('Full Table', 'Full Table'[File] = SELECTEDVALUE('File Slicer 1'[File]))) VAR Table2 = CALCULATETABLE(VALUES('Full Table'[String]), FILTER('Full Table', 'Full Table'[File] = SELECTEDVALUE('File Slicer 2'[File]))) RETURN IF(OR(COUNTROWS(EXCEPT(Table1, Table2)) =1, COUNTROWS(EXCEPT(Table2, Table1)) =1), 1)4) Create a measure to return the file namefor each row based on the previous measure
File with unique row = CALCULATE(SELECTEDVALUE('Full Table'[File]), FILTER('Full Table', [Different Rows] =1))You can now create a visual using the fields from the table and this [File with unique row] measure:
This table will display the rows which are unique to both of the files selected in the slicers.
5) to get the rows which have differing values in some columns is more tricky. For my example, which the files have only 3 columns, I created this measure to use as a filter:
Rows with diff values = VAR Channel = CALCULATE(COUNT('Full Table'[Channel]), FILTER(ALLEXCEPT('Full Table', 'Full Table'[Channel]), [Different Rows] = 1)) VAR _Item = CALCULATE(COUNT('Full Table'[Item]), FILTER(ALLEXCEPT('Full Table', 'Full Table'[item]), [Different Rows] = 1)) VAR _Code = CALCULATE(COUNT('Full Table'[Code]), FILTER(ALLEXCEPT('Full Table', 'Full Table'[Code]), [Different Rows] = 1)) RETURN Channel + _Item + _CodeYou can then make a copy of the main visual and add this measure in the filter pane for the visual
I have set the threshold to greater than 3 because my dataset has only three columns (apart from the calculated column for "String" I added later). You will need to alter the measure to cater for the number of columns and adjust the threshold accordingly.
This is the final result:
I've attached the sample PBIX file for your reference
Here is one way. (Apologies since I worked on a sample dataset)
1) Create two disconnected tables to use as slicers with the unique values for the file names. Here is what my model looks like:
2) add a column ("String" in the my example) which concatenates the values of each column in the table containg the appended rows from all the tables
3) Create a measure to use in the filter pane for slicer 2. This filter will filter out the values we select on slicer 1 from slicer 2:
Filter Slicer 2 = COUNTROWS(EXCEPT('File Slicer 2', 'File Slicer 1'))
3) Create a measure to return the rows which are not present in both tables
Different Rows =
VAR Table1 = CALCULATETABLE(VALUES('Full Table'[String]), FILTER('Full Table', 'Full Table'[File] = SELECTEDVALUE('File Slicer 1'[File])))
VAR Table2 = CALCULATETABLE(VALUES('Full Table'[String]), FILTER('Full Table', 'Full Table'[File] = SELECTEDVALUE('File Slicer 2'[File])))
RETURN
IF(OR(COUNTROWS(EXCEPT(Table1, Table2)) =1, COUNTROWS(EXCEPT(Table2, Table1)) =1), 1)
4) Create a measure to return the file namefor each row based on the previous measure
File with unique row =
CALCULATE(SELECTEDVALUE('Full Table'[File]), FILTER('Full Table', [Different Rows] =1))
You can now create a visual using the fields from the table and this [File with unique row] measure:
This table will display the rows which are unique to both of the files selected in the slicers.
5) to get the rows which have differing values in some columns is more tricky. For my example, which the files have only 3 columns, I created this measure to use as a filter:
Rows with diff values =
VAR Channel = CALCULATE(COUNT('Full Table'[Channel]), FILTER(ALLEXCEPT('Full Table', 'Full Table'[Channel]), [Different Rows] = 1))
VAR _Item = CALCULATE(COUNT('Full Table'[Item]), FILTER(ALLEXCEPT('Full Table', 'Full Table'[item]), [Different Rows] = 1))
VAR _Code = CALCULATE(COUNT('Full Table'[Code]), FILTER(ALLEXCEPT('Full Table', 'Full Table'[Code]), [Different Rows] = 1))
RETURN
Channel + _Item + _Code
You can then make a copy of the main visual and add this measure in the filter pane for the visual
I have set the threshold to greater than 3 because my dataset has only three columns (apart from the calculated column for "String" I added later). You will need to alter the measure to cater for the number of columns and adjust the threshold accordingly.
This is the final result:
I've attached the sample PBIX file for your reference
PaulDBrown
Thank you so much for your reply, it's so full of valuable informations for me!
I will take my time now to study it, and hopefully I'll be able to adapt it to my specific needs - in fact the example you provided is EXACTLY what I was looking for - again, THANK YOU!