Marty Cochrane
Marty Cochrane

Reputation: 689

Read excel cell colour into Power BI

I have an excel file that I need to read into Power BI. Unfortunately I have no control over this file as its auto generated from another person.

Some of the cells in this file are just filled with colours and I want to be able to translate these colours when importing the data into Power BI.

For example if the colour is green in excel then show true in the corresponding power BI cell. At the moment it's just blank.

Does anyone know of a way to get cell "meta" data like colour from excel in Power BI?

Upvotes: 2

Views: 8765

Answers (2)

Ben
Ben

Reputation: 1295

Don't give up just yet...

I found an example that works in a roundabout way using Power Query in Excel. It will give you the meta data associated with each cell by its address (e.g. A1 is highlighted with color FFFFFF00). I relied on some Excel functions to associate the highlighted cell addresses with the cell values. Pulling the cell data with Power BI might take some additional work.

The technique is to use Power Query to open the Excel .xlsx file, which is basically a .zip file containing .xml documents. The color information for each cell can be extracted into a table. From there I was able to use INDIRECT() statements to read from the .xlsx workbook and extract the values from the colored cells. It worked quite well for me.

You can find a working example in the forum in the link below. The user defined DecompressFiles function in the sample uses the Binary.Decompress command to access the XML files within the .xlsx file.

https://www.excelguru.ca/forums/showthread.php?7047-Extract-Cell-Color-with-M&p=28875&viewfull=1#post28875


In my situation, I had a database export of about 7,000 rows and 50 columns into Excel. Working offline, users then went through Excel and made changes, highlighting every cell they had changed. Then they wanted me to update the database with only the highlighted cells. The background color used by each person varied but I didn't care what the color was, just that it was colored.

For each changed cell I was able to generate SQL statements to update the database and also insert into a transaction log table. The main database table was mostly flat but the few foreign key lookup values that were modified I had to update manually.

enter image description here

Column F uses the Indirect formula to pull data from the source workbook. Note that the source workbook must be open for the Indirect formula to read from it. =INDIRECT("'[" & Import_Filename & "]" & Sheet_Name & "'!"&[@[SheetCellRef.2]])

Column G refines the data in Column F by putting quotes around strings or NULL if the cell is blank.

Column H grabs the column heading to know what field to update.

Column K grabs the Record ID value from the row specified in Column E.

I have had to run this process three different times for the users so my time invested paid off quickly. All I have to do is put their latest highlighted Excel file in the local folder and refresh the Power Query to generate new SQL statements.


Sorry I don't have a 'solution' posted right here. The process is still a little fragile and I'm trying to make a more robust example I can share. Stack Overflow doesn't seem to be set up for ongoing development of a solution. The point of this answer is to give hope to some of you who are desperate for a solution and won't take 'No' for an answer.

Upvotes: 3

teylyn
teylyn

Reputation: 35915

Sigh.

Color is not data. Unfortunately, many people color-code cells and then expect to be able to do things based on the color of the cell. But it's not that simple.

Although Excel now provides some ways to filter by cell color, it still cannot identify cell color with a worksheet formula.

Hence, you will need a VBA routine that evaluates all cells and records their colors in another table, which you will then need to push into your Power BI data model.

In the long run, it might be easier to talk to that other person who produces the color coded cells, and teach them a better way of doing things. Show them how to use conditional formatting based on cell values for color coding. The logic used for conditional formatting can also be applied to classify the data in Power BI.

From a data architecture point of view, the best solution is to address the problem at the source, instead of creating tools to handle bad data input.

Just sayin'.

Upvotes: 1

Related Questions