Deneb Exercise - Calendar Heat Map

I saw a Calendar Heat Map visual a while ago in a LinkedIn post by Bolaji Olatunde using a standard Power BI matrix

and wondered if Deneb/Vega-Lite could produce a similar type of graphic. Here’s what I came up with:
deneb.calendar_heat_map.0.2

This example uses a number of optional Deneb/Vega-Lite components, including:

  1. a title block
  2. a transform block to extend the dataset
  3. a facet (like small multiples) for months with:
    • definition: quarters on rows, month in quarter on columns
    • specification: vertical concatenation of a text mark for month name and a nested layer for:
      • rectangle mark for the day of the month using a gradient colour fill based on the number of sales on that day (light blue to dark blue); legend visible (top-right, vertical)
      • text mark for the number of the day of the month using inverted gradient colours (light when number of sales is above 10, dark when number of sales is below 10); legend hidden
  4. a custom tooltip on each rectangle mark showing day, month, date, year, and number of sales

For expediency, 3 simple Power BI calculated columns were added to the [Dates] table to create additional values to make the months/weeks/days display correctly:


Day of Week Number 2 = 
/*
To permit proper day of the week sorting in the Deneb visual,
convert the 0-6 Monday-to-Sunday to 0-6 Sunday-to-Saturday
by adding 1 and wrapping
*/
VAR _NewNumber = Dates[Day of Week Number] + 1
VAR _Result = IF( _NewNumber = 7, 0, _NewNumber )
RETURN
_Result

Month of Quarter = 
/*
Calculate the placement of the month within the quarter
*/
VAR _CurrentMonth = MONTH( Dates[Date] )
VAR _CurrentQuarter = QUARTER( Dates[Date] )
VAR _Result = _CurrentMonth - ( _CurrentQuarter - 1 ) * 3

RETURN
_Result

Week of Month = 
/*
1. Extract the 'week of year' from the date
2. Extract the 'week of year' from the date of the first day of the month the date falls within
3. Subtract the two week numbers and add one (so that the first week does not appear as zero)
*/
VAR _CurrentWeek = WEEKNUM( Dates[Date] )
VAR _WeekOfFirstOfTheMonth = WEEKNUM( DATE( YEAR( Dates[Date] ), MONTH( Dates[Date] ), 1 ) )
VAR _Result = _CurrentWeek - _WeekOfFirstOfTheMonth + 1

RETURN
_Result

The intent of this exercise is not to provide a complete solution for finished visuals, but rather to serve as a starting point for further custom visual development.

Also included is a sample PBIX using the Enterprise DNA Practice Dataset as a demo.

NOTE: This exercise is provided as-is for information purposes only, and its use is solely at the discretion of the end user; no responsibility is assumed by the author.

Greg
Deneb - Calendar Heat Map.pbix (2.1 MB)

4 Likes

marking as solved