Blogs

Blogs

Python Datetime Module: All You Need to Know

Python datetime is a module to work with dates in python which consists of four main classes which are: date, timedelta, time, and datetimes. We’ll implement how each of these objects can be used in our code. The Date Class The object represents a date which is an attribute of the year, month and day in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions whereby January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on. The constructor of this class is represented as class datetime.date(year, month, day). For instance, we can have; from datetime import date # date object of today’s date today = date.today() print(“Current year:”, today.year) print(“Current month:”, today.month) print(“Current day:”, today.day)   The TimeDelta Class Python timedelta class is used for calculating differences in dates and times. This timedelta supports mathematical operations like additions, subtractions, multiplication, division etc. The constructor class for TimeDelta; class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) Calculating difference between two date and times # Timedelta function demonstration from datetime import datetime, timedelta # Using current time current_time= datetime.now() # printing initial_date print(“date_now”, str(current_time)) # the other datetime result_date = current_time + \ timedelta(days=5) # printing new result_date print(“new_result_time”, str(result_date)) # printing calculated past_dates print(‘Time difference:’, str(result_date -current_time))   Different Operations supported by TimeDelta class Operator Description Addition (+) Adds and returns two timedelta objects Subtraction (-) Subtracts and returns two timedelta objects Multiplication (*) Multiplies timedelta object with float or int Division (/) Divides the timedelta object with float or int Floor division (//) Divides the timedelta object with float or int and return the int Modulo (%) Divides two timedelta object and returns the remainder +(timedelta) Returns the same timedelta object -(timedelta) Returns the resultant of -1*timedelta   The Time Class The time class of python datetime module represents a time quantity. The time class usually contain a tzinfo representing the timezone for which the time is specified. We must note that the date class doesn’t possess attributes related to time, also the time class doesn’t have date information, it’s only the dateclass that has both attributes pertaining to date and time. The constructor class for Time is; class datetime.time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0) An example of how we can represent time by calling the time constructor is shown below. Representation of Time and obtaining hours, minutes, seconds, and microseconds from datetime import time # calling the constructor my_time = time(13, 24, 56) print(“Entered time”, my_time) # call the constructor with just one argument my_time = time(minute=12) print(“result with one argument”, my_time) # Calling constructor with no argument my_time = time() print(“Time with no argument”, my_time) Time = time(20, 25, 50) print(“hour =”, Time.hour) print(“minute =”, Time.minute) print(“second =”, Time.second) print(“microsecond =”, Time.microsecond)   The DateTime Class The DateTime class contains information on both date and time. The constructor class for the datetime class is ; class datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)  Note: The year, month and day are very mandatory. The tzinfo can be set as None while the other attributes must be an integer. Representation of the Datetime class, get year, month, hour, minute, and timestamp # A program to demonstrate datetime object from datetime import datetime # call the constructor one = datetime(2001, 10, 12) print(one) # call the constructor with time parameters as well two = datetime(2001, 12, 10, 12, 12, 12, 212390) print(two) #call the year, month, hour, minute, timestamp a = datetime(2001, 12, 10, 12, 12, 12) print(“year =”, a.year) print(“month =”, a.month) print(“hour =”, a.hour) print(“minute =”, a.minute) print(“timestamp =”, a.timestamp())   We have the following Date class methods which we can use, you can check the documentation to get more. Function Name Description now() Returns current local date and time with tz parameter replace() Changes the specific attributes of the DateTime object strftime() Returns a string representation of the DateTime object with the given format strptime() Returns a DateTime object corresponding to the date string time() Return the Time class object timetuple() Returns an object of type time.struct_time timetz() Return the Time class object today() Return local DateTime with tzinfo as None   Converting DateTime to Strings We also need to convert our datetime to strings which can be for different reason. To convert datetime to strings, we will use the datetime.strftime and datetime.isoformat methods. Using ISO Format >>dt = datetime.now() >>print([dt.isoformat()]) [‘2022-03-16T16:23:21.505760’] Using the String Format time Method (.strftime format) >>> print(dt.strftime(‘Today is %Y, %B %d’)) Today is 2022, March 16 >>> print(dt.strftime(‘Date: %d/%m/%Y Time: %H:%M:%S’)) Date: 16/03/2022 Time: 16:28:54 These dates are usually in the form YYYY-MM-DD T HH:MM:SS.Microseconds The following are time format codes in Python which we can explore: %Y: the year in 4 digits %y: the year in 2 digits %m: month in 2 digits %B: full name of the month %w: week number from 0 to 6 %A: full name of the weekday %a: first three letters for the weekday %W: returns the week number of the year %d: day of the month %j: day of the year %H: hour %M: minute

Blogs

How to use KPI Visuals in Power BI

A Key Performance Indicator (KPI) is a visual cue that communicates the amount of progress made toward a measurable goal or shows how effectively you’re meeting your goals. KPI visual is a functional and effective visualization in Power BI. KPI Elements in Power BI Key Performance Indicators can be broken into three parts; Base value, Target value, and Status thresholds. Base value: a base value is a calculated field that usually results in a value or result, for example, it can be an aggregate of profit or sales for a specific period of time. Target value: The target value is a measure which is the goal all the rows should achieve. E.g. Sales target for all the salespersons. For instance, we can set a target value for entire units to be sold in a month as 500. Now, our base value will be the recorded value for a month. It can be less than 500, equal to 500, or greater than 500. Status thresholds: The status thresholds provide a rank to evaluate the base value and target values. The visual also presents a high and low threshold between which the base and target values fall to help users determine the status of the base value to the target value. Note: A KPI dataset also needs to contain goal values for a KPI. If your dataset doesn’t contain goal values, you can create them by adding an Excel sheet with goals to your data model or PBIX file How to Create a KPI in Power BI Desktop Open your report editor in Power BI Desktop then select a report on which you are working. On your right, you will see your Visualization pane and Fields pane. Navigate the Visualizations pane and select the KPI visual. After you’ve selected the KPI visual, three blank spaces are present in the Fields section; Indicator, Trend axis, and Target measure. We will go back to the Fields pane and find out all our data has been brought in. Select the field values (from table TotalSalesThisYear) and put them into the Indicator column. Then we will put the field FiscalMonth in the Trend axis column and the Goals field into the Target measure column. From the image below, this represents a sample KPI we’ll generate. We’ll go further to format the KPI by selecting the paint roller icon i.e. the Format section. Under here we can set the properties of our indicator, goal, trend axis, etc. After we’re done formatting the KPI to our desired output, we’ll generate a sample KPI that looks like what we have in the image below. KPI Custom Visualizations The KPI we created now is known as the Built-in KPI which comes with our Power BI Desktop. In addition to this built-in KPI, we have several other KPI-related visualizations that we can download from the Power BI Marketplace. To add custom KPI visualizations from the marketplace, we click on From Marketplace icon. From the Power BI Visuals dialog box, we have all the different types of available add-in visualizations to use. To view these related visuals, go to KPIs option and select from the list of visuals like Bullet Chart, Dual KPI, Power KPI, etc. KPI best practices There are different KPI best practices that we can observe to help us explore more on KPI usage. These tips are; You must only pick KPIs that are aligned to your specific goals. If your objectives aren’t clear, matching KPIs against them will prove complicated. Ensure you use different KPIs for the same goals if they stretch across groups. Ensure that whatever KPI you selected, there’s a core team responsible for defining them.

Blogs

10 Power BI Tips for Designing a Better Dashboard

The Power BI is an interactive data visualization software product developed by Microsoft with a primary focus on business intelligence. Power BI enables users to drill down into their data to gain deeper insights and make more informed decisions. This data is usually displayed in reports and dashboards. The following tips below are what we can use to design a better dashboard; Consider your audience The first thing which must take place when designing a dashboard is the consideration of the audience, whereby you need to know the information your audience will need to improve their business decisions. When designing our dashboard, we also need to know the device the audience will be viewing the dashboard from, is it from a desktop or tablet, putting this in place helps to know how to do a proper arrangement of our dashboard design.      2. Use the right visualization for the data When producing your visualization, you must make it easier to read and interpret. You must also ensure to avoid the use of different varieties of visualization in order to make it look simple, so as to pass the right message to the audience. The use of appropriate title headers, labels must be used, to make it easier for the audience to read.    3. Avoid over-complicating the dashboard Your dashboard must paint a single picture. You must avoid the use of scroll bars, your audience must be able to glance through your dashboard at once. The dashboard shouldn’t be too overcomplicated, you can remove any non-essential thing present on the dashboard.   4. The page layout You must always provide a layout for your dashboard, so your contents can be well placed. The contents on the dashboard can be placed in a left to the right manner, whereby the most important information is placed at the top.   5. Use Tooltips The tooltip is a very good function to add to a dashboard. It makes the reader grab the most important information they need about the dashboard and as well allows them to drill down more information with just a click.   6. Use bookmarks Using bookmarks is very good to maintain a conservative design while the user still has as much information needed. The bookmarks are useful for hiding visualizations.   7. Use a full-screen mode The full-screen mode is very useful for presenting to the audience, with this it helps to cover the dashboard on a wider view, which also helps to prevent distractions.   8. Use filters and slicers The use of filters and slicers needs to be encouraged in a report. This helps to improve the look and ease of use of the report.   9. Use a theme The use of a theme in a report will definitely make your report more solid. A theme includes colors, background, fonts e.t.c.   10. Page navigation We can as well provide page navigation for our report. You can, for example, add another view, something like tabbed page navigation which allows users to navigate through the landing page to the detailed report pages.

Blogs

How to Set up Row-Level Security in Tableau

It is possible to restrict users’ views when you share workbooks to Tableau Server or Online. Those who have access to the workbook are the only ones who can see the data shown in the view. We can demonstrate this by using the row-level security in Tableau. Here, we apply a type of filter that allows users to specify which data any given person signed in to the server can view. How to Set up User-based Filtering We’ll be using one of our sales reports to demonstrate this. In this report, let’s say we’ll like to show the number of sales for different geographical regions. Also, we just want to assign each of our users to view their own designated region whenever they view the report. The users won’t have access to other regions except for the ones they were given access to, we will follow the steps below on how to make this happen; 1)We first publish our report to the Tableau Server. 2)The next thing we need is to create a user filter for our report, we then locate the Server on the menu tab and click on Create User Filter 3)Under the create user filter, we will create users to assume the exact region data they will have access to view. Therefore one user maps to any given row of data. 4)After we’re done we then add our Manager with Region filter we created to the Filters Pane. 5)After this, we put this in a dashboard and publish it again to the server. We must ensure to apply our filter to be active on all worksheets using the related data source, so all users can view data designated to them. Note, Tableau offers the following approaches to row-level security: Create a user filter and map users to values manually; This applies to an example we demonstrated above. This method is convenient but high maintenance. It must be done per workbook, and we must ensure to update the filter and republish the data source as our user base changes. Create a dynamic filter using a security field in the data; In creating a dynamic filter, we create a calculated field that automates the process of mapping users to data values. This method usually requires that the underlying data include the security information we want to use for filtering. The most common way to do this is to use a reference (“look-up,” “entitlements,” or “security”) table that contains this information. We must also know that Row-level security with extracts is faster to create and have better performance than Row-level security with data sources that use live connections. How do you secure your data in Tableau? Let us know in the comments section.

Blogs

How to Set up Row-Level Security in Power BI

What is Row-Level Security in Power BI? Row-level security in Power BI is a way to restrict the kind of data an end-user views in a Power BI report. The use of filters is usually used to limit data access at the row level and we can as well define filters within the roles. In the Power BI service, members of a particular workspace can have access to datasets in the workspace; row-level Security doesn’t restrict this data access. Defining Roles & Rules in Power BI Desktop The following steps will guide us on how to define roles in our Power BI Desktop; Open report   2)From the Modeling tab, select Manage Roles.   3)From the Manage roles window, select Create.   4)Under Roles, you provide a name for the role. 5)At Tables, select the table you would like to apply a DAX rule. 6)In the Table filter DAX expression box, enter the DAX expressions, just like what we have in the picture below After the DAX expression has been created, select the checkmark above the expression box to validate the expression. 7)Select Save The next step is to validate our role on PowerBI Desktop by navigating to the Modelling tab and selecting view as The View as window then appears as this whereby we can then select the checkmark for our created role and then click ok The report for the FRANCE country then opens as shown below; We then move to how we can validate our role on the Power BI service. We also need to know that the roles we applied to this report will definitely take effect after we have published it. How to Validate Role on Power BI service After we have designed our report, we then publish it to Power BI service, by selecting Publish on the Home Tab After this report has been published, we’ll open Power BI service to check our report and then we move to manage security on our Data model. To do this, we will carefully follow the steps below; 1)In the Power BI service, select the More options menu for a dataset. 2)Select Security. 3)Under the security, it takes us to the Role-Level Security page where we can add members to the role we created in Power BI Desktop. Only the owners of the dataset will see the Security. After we have added the members by typing in the email address, we then select Add and save We can also type in name of the user or security group when adding members but we can’t add Groups created in Power BI. Members external to your organization can be added as well. The following groups below are usually used in setting up row-level security. Distribution Group Mail-enabled Group Security Group Also Note, if the dataset is in a Group, only administrators of the group will see the security option. You can only create or modify roles within Power BI Desktop.

Blogs

Creating Paginated Reports in Power BI Report Server

Paginated reports are reports created to be printed or shared. From the name, they are formatted to fit well on a page. Paginated reports can be used to run many pages and are usually laid out in a fixed format which has detailed customization. They are stored and managed on the Power BI Report web portal and we can edit them using the Report Builder. This report can as well be viewed on the browser or on a mobile device. In this post, we will learn how to create paginated reports in Power BI report server. How to create Paginated Reports using Report Builder The first step is to install a report builder to create reports for Power BI Report Server. We can install using the procedure below; Navigate to the Power BI Report Server web portal Select New Select Paginated Report. This will guide you through the installation process. After it has been installed, Report Builder opens to the New Report or Dataset screen. We then Select the wizard for the kind of report we’re interested in creating which might be table or matrix, chart, map e.t.c. The Chart Wizard Let’s demonstrate further by clicking on the chart wizard to show how we can create a visualization in a report. After selecting the Chart wizard, we will see “Choose a dataset”, bring in our dataset or choose a shared dataset on a server. Then choose our chart type. For example, Bar, Column, Area, Line. We will use the Bar chart type in this tutorial. Afterwards, we arrange the fields by dragging them to the Categories, Series, and Values boxes. we then Select Next → Finish Design your report Now we’re now in the Report design view where we take a step further to design our report. We can view our data by clicking on Run and as well go back to the Design view by selecting Design. There is an availability to modify our chart to what we want exactly by changing the layout, legends, values and also add any visualization ranging from map, matrixes, tables e.t.c. You can also add headers and footers for multiple pages. Save the Report to Report Server When we’re done working on our report, we can save it to the Power BI Report Server using the following; Open the File menu. Select Save as, and save it to the report server Afterwards, you can view your report on the browser. Conclusion In this post, we have learnt how to create paginated reports in Power BI by following the steps above.

Scroll to Top