Friday, October 31, 2025

SVGs, Floor plans in PowerBi

We had a business requirement to show charts with regions. For the first use case we had to show body injury data and what we had was an SVG that had all the body injury locations.

We looked at a lot of solutions:

1. Storing the SVG data in a table/measure and displaying it.

This did not work, as the SVG data I could only get to display in a table visual and that would be very small for our use case. Additionally we wanted to be able to pick locations and display regions with color coding.

2. Using the ShapeMap.

I tried to convert the SVG vector to TopoJson, but nothing seemed to be able to convert the SVG to a good TopoJson. I even tried to trace the SVG into a vector file using QGIS and then convert it to a TopoJson file. But it always ended up looking like a "Picaso Painting"



3. Custom Visual:
There are a few different custom visuals available and we were investigating Synoptic Panel from Okviz). This would probably work, but if you had a lot of shapes, regions, then it would cost a per user license.

Final Solution:
The final solution actually turned out to be the easiest (the only requirement is that you need to have Visio online).

Here are the details: Add Visio Visuals to Power BI reports - Microsoft Support

And here is what it can look like:

One reason that this is a really good solution is that if you have a drawing that might frequently change (example floor map), then all you have to do is edit the visio diagram in Visio Online and if you open up the PowerBi dashboard, the changes immediately show up.

How we did it: Its simple, create a new visio diagram and insert the SVG. As long as your SVG was made up of different parts, the svg will come in as a vector. You will have to ungroup your vector and you can make changes. For PowerBi to be able to color the image, the transparency for each part needs to be set to 0%. One thing I could not figure out is, how Power Bi determined as the page to use for the visual. It seemed like which one was the last one being edited would be picked. This felt dangerous, as if someone edited the diagram, it could impact the dashboard. So, we went with the option of a separate visio file for each diagram we wanted to include in PowerBi.

We will be investigating this option more, but I wanted to put this out there as a potential solution.


More info:


Friday, May 30, 2025

PowerBi + Aws Athena + Dataflow Error: Incorrect number of arguments

 A dataflow that I had suddenly stopped work.

The error was 

Encountered user gateway exception: '<ccon>ODBC: ERROR [HY000] Incorrect number of arguments: </ccon>

After a lot of troubleshooting, I figured out it was being caused by some steps I had added to add additional columns. Most likely, those steps were being query-folded to the database and it was not working.

I solved it by adding a call to Table.StopFolding right before I added the steps.

Table.StopFolding - Table Function | Power Query M



Wednesday, April 09, 2025

AWS Lambda error: Sandbox.Timedout 3.00 Seconds

In a AWS lambda, we suddenly started seeing this error:

 {

  "errorType": "Sandbox.Timedout",

  "errorMessage": "RequestId: xxxxxx-xxxx-xxx-xxxxxxxxxxx Error: Task timed out after 3.00 seconds"

}

The "Sandbox.Timeout" threw me and I could not figure out where it was coming from.

Turned out, the error was being thrown by the AWS Lambda Infrastructure, because it was configured to run for only 3 seconds. This is done via the Configuration tab and editing the "General Configuration" and increasing the timeout setting.



Tuesday, April 01, 2025

PowerBI + PostGreSql + AWS-RDS

 I was getting an error when trying to connect using the PostGreSQL connector in PowerBi.

    The remote certificate is invalid according to the validation procedure

The basic solution is informed by this AWS post: Set up SSL/TLS client connections to Amazon RDS for SQL Server and Amazon RDS for Oracle | AWS Database Blog, but I found it didnt work exactly the way in that post (PEM file didnt work).

Luckily for us, AWS now provides a PKCS7 file. So, go to Using SSL/TLS to encrypt a connection to a DB instance or cluster - Amazon Relational Database Service and download the bundle appropriate for your AWS Region. (You can use the global bundle, but the problem with that is you will have to hit approve in the Import Wizard many times (approximately 3 for every zone)). So, using your region's cert bundle will lessen the number of clicks.

Once downloaded, you will have to open your Windows Certificate Manager (Windows >> Run >> CertMgr.msc).

In the CertMgr, click on "Trusted Root Certification Authorities" >> Certificates and then Import.

In the Import Wizard, you will have to find the P7B file you downloaded from AWS and import it. Approve the next few steps. You should now be able to connect to PostgreSql running AWS-RDS.

These steps should also work for connecting SQL Server to PostgreSql in AWS.




Wednesday, December 11, 2024

Microsoft Forms: Difference between a Form and a Quiz

 In Microsoft Forms you can create a "Form" or a "Quiz". But what is the difference between the two?


In a quiz, you can specify the correct answer and the points for the answer, if correct.


Where for a Form, you cannot provide the correct answer, nor can you assign the question a score.


Also, with a quiz, you can do some cool things like enter equations for Math questions:

A quiz also has some additional settings that allow you to show answers, etc:





Saturday, August 17, 2024

Select Blinds Ac 114 remote pairing/copy code to new remote

Select Blinds Ac 114 remote pairing/copy code to new remote


Works for AC114-06B and 02B remotes.


Paired remote: the one that currently is programmed and working 

New remote: the one you wish to program


Steps:

1. Select the channel on the paired remote that you wish to copy to new remote

2. Select the channel on the new remote 

3. Press stop button once on paired remote and then press and hold until the blinds jog up and down once

4. Quickly on the new remote press up button. Blinds should jog to let you know the code got copied.


Manual: https://drive.google.com/file/d/1mcOqt3M_EZQjjxoddzVfIvbzJvrlqGQ3/view?usp=drivesdk





Monday, April 15, 2024

Windows 11 - Enabling Hibernate

 If Hibernate is not available as an option, the following 2 commands run from PowerShell should enable it:


1. powercfg /hibernate on

2. powercfg /h /type full

The above commands need to be run from a Administrator Powershell window.

In Windows 11, you can then go to: Start >> Type: Control Panel >> Control Panel >> Power Options >> Choose what the power buttons do.

Thursday, January 18, 2024

AWS - MWAA - Customize UI Title

If you would like to customize the Airflow UI title to include some additional information, you can do so in MWAA by setting webserver.instance_name 


This will update the Title bar to show the value you set as shown below:



Monday, October 23, 2023

AWS Athena - Using Merge + Iceberg tables to store only changed records

This post is based on my github page: mypublicnotes/AWS/Athena/iceberg_tracking_changes.md at master · rajrao/mypublicnotes (github.com)

Change data capture using Athena and iceberg

Many times in a datalake, you have a source, where the source doesnt provide information about which records changed. Another use case is where you have an ETL, where you have multiple tables and columns taking part in it and its traditionally difficult to track which records changed in that ETL query. This page shows you one method for being able to track those changes and insert only those records that are new or had updates. (at the end, I also show how to track deletes). The method leverages AWS Iceberg tables in Athena (Athena Engine 3) and the upsert mechanism provided via the merge-into statement.

TL;DR; Check out the merge statement used to update only those records that had changes.

Setup: A CTE for source data

I am using a CTE to simulate source data, in practice, you would typically use another Athena table as your source, or a query that brings data together from multiple tables (aka ETL), etc. A key part to this method is using a hashing function that can be used to determine when a record has changes. I use xxhas64

with cte(id, value1, value2) as
    (
    select 1,'a1','b' union all
    select 4,'raj','rao' union all
    select 2,'c2','d2' 
    )
    select *, xxhash64(from_base64(value1 || value2)) as hash from cte

Note 1: You can use murmur3 instead of xxhash64 using the following code: murmur3(to_utf8(value1 || value2)).

Note 2: Here are the other hashing functions available: https://trino.io/docs/current/functions/binary.html

Setup: Create an iceberg table

The iceberg table is your final table. This will track the data that had changes. Id is the primary key in this case, you can have more columns that are part of the primary key used for the update.

CREATE TABLE
  test_db.hash_test (
  id int,
  value1 string,
  value2 string,
  hash string,
  last_updated_on timestamp)
  LOCATION 's3://my_test_bucket/hash_test'
  TBLPROPERTIES ( 'table_type' ='ICEBERG')

The ##Merge## statement

Here is a merge statement that inserts new records and updates only when there are changes. The merge statement uses the CTE described above as its source data. You can manipulate the CTE to test various scenarios. The hash column is used to determine when to insert/update data.

MERGE INTO hash_test as tgt
USING (
    with cte(id, value1, value2, value3) as
    (
    select 1,'a1','b',100 union all
    select 4,'rao','raj',200 union all
    select 2,'c2','d2',300 
    )
    select *, xxhash64(to_utf8(concat_ws('::',coalesce(value1,'-'),coalesce(value2,'-'),coalesce(cast(value3 as varchar))))) as hash from cte
) as src
ON tgt.id = src.id
WHEN MATCHED and src.hash <> tgt.hash
    THEN UPDATE SET  
    value1 = src.value1,
    value2 = src.value2,
    hash = src.hash,
    last_updated_on = current_timestamp
WHEN NOT MATCHED 
THEN INSERT (id, value1, value2, hash, last_updated_on)
      VALUES (src.id, src.value1, src.value2, src.hash, current_timestamp)	  

If you need to deal with deletes, you can add as your first matched phrase one of the following options (delete, or archive):

WHEN MATCHED and src.IsDeleted = 1
  THEN DELETE

or

WHEN MATCHED and src.IsDeleted = 1
  THEN UPDATE SET  
    is_archived = 1,
    last_updated_on = current_timestamp

Finally some examples of queries to view the data

-- see the history of changes
select * from test_db."hash_test$history" order by made_current_at desc

-- use a snasphot_id from above as your value for xxxxx
select * from test_db.hash_test for version as of xxxxx

-- get only the latest records from the table
select * from test_db.hash_test
where last_updated_on in (select max(last_updated_on) from test_db.hash_test)
order by last_updated_on

Reference:

  1. Athena Functions
  2. Query Delta Lake Tableshttps://docs.aws.amazon.com/athena/latest/ug/delta-lake-tables.html)
  3. Using Apache Iceberg tables

Testing Hashing Behavior

When hashing you need to make sure that null values are handled appropriately.

Ex: null, a, null and a, null, null should be treated as changes. If they generate the same hash, then you will miss this change. Also the hash functions need string input and hence, one needs to cast the data when its not of type string. For this reason, the computation of the hash gets complicated and I have not found a simpler solution around this.

with cte(id,note, value1, value2,value3) as
(
    select 1,null,'a1','b',1 union all
    select 4,null,'raj','rao',2 union all
    select 5,'both null',null,null,null union all
    select 6,'empty & null','',null,null union all
    select 7,'null & empty',null,'',1 union all
    select 8,'empty-empty','','',2 union all
    select 9,'str-null','a',null,3 union all
    select 10,'null-str',null,'a',4 union all
    select 100,null,'c2','d2',5 
)
select *
,concat_ws('::',coalesce(value1,'-'),coalesce(value2,'-'),coalesce(cast(value3 as varchar)))
, murmur3(to_utf8(concat_ws('::',coalesce(value1,'-'),coalesce(value2,'-'),coalesce(cast(value3 as varchar))))) as hash1
, xxhash64(to_utf8(concat_ws('::',coalesce(value1,'-'),coalesce(value2,'-'),coalesce(cast(value3 as varchar))))) as hash2
from cte
order by id




Tuesday, July 18, 2023

PowerBi/PowerQuery: Dealing with errors in Excel files

 When you have errors in your excel file, they sometimes leak through and adding "Table.ReplaceErrorValues" or "Table.RemoveRowsWithErrors" doesnt really work. What I have found is to add the error fix step right after the navigation step that loads the sheet. 

In the screenshot below, I have used "Table.RemoveRowsWithErrors" after the Navigation step and it fixed the error.