Creating the session
Let’s start by creating an Atoti session and loading some data into it:Querying the session
The first query will retrieve the values of a few measures for each Sub category and Brand.Styling tables
The result of this first query will be displayed as a table in our report. We’ll use three different techniques to style it:Defining cell properties in the MDX query
In the query below, we use calculated measures to style the table cells. In particular,FORE_COLOR=IIf([Measures].[Count] < 300, RGB(255, 135, 135), NULL) in the following query ensures that the cells for the contributors.COUNT measure are colored red if their value is less than 300.
Applying style with pandas
pandas provides many ways to style a DataFrame. Here, we’ll apply a background color to a specified row:Adding style with CSS
Before being a PDF, our report will be an HTML file so we can use CSS to style it:Creating the chart
Many Python libraries can create charts from pandas DataFrames. In this how-to, we’ll use seaborn which is a wrapper around Matplotlib:Creating the HTML report
We’ll use Jinja to render this template:Exporting the report as a PDF
WeasyPrint can render HTML as a PDF:Going further
The report could be sent by email periodically using the schedule library or:- Task Scheduler on Windows
cronon Linux or macOS- A Lambda function in the cloud