BLOGS

ByHariharan Rajendran

Capture the Selected Filter in PowerBI – DAX

As PowerBI has various options to slice and dice the data, it is very mandatory to understand the filter context on the PowerBI report.

Filter Context can be applied on various levels

  1. Row & Column Headers
  2. Slicers
  3. Filters (Visual, Page & Report level)

Let us take a scenario where the user wants to capture the filters applied to the specific field.

To demonstrate this scenario, I create a simple table as like below.

I need to use Description field on the table to filter the data.

Description field on Slicer

If the user selects the checkbox then it should show the selected value. If it is a single selection, then show the value. If users select multiple values, then show as “Mulitple”.

Description field on Filter (Page level Filter)

Place the description field on the page level filter and see the outcome.

Use the below DAX script to achieve the result.

Parameter Selection =
IF (
HASONEVALUE ( Parameters[Value] ),
“Selection” & VALUES ( Parameters[Description] ),
IF (
NOT ( ISFILTERED ( Parameters[Description] ) ),
“No Selection”,
“Mulitple Selection”
)
)

ByHariharan Rajendran

Year to Date calculation in DAX

This post explains how to achieve Year to Date calculation using DAX script.

In DAX, there is a pre-defend function available to get the Year to Date calculation. Also, for the quarter to date & month to date.

Those functions are

TOTALYTD()

TOTALQTD()

TOTALMTD()

Instead of using the pre-defend functions, we can use our own defined function like below. To achieve the YTD calculations, use the below functions

  1. CALCULATE
  2. FILTER
  3. ALL

Let us consider a field called “Total Sales”. We will be used the Total Sales & “Date” table.

YTDSales = CALCULATE([Total Sales],

                      FILTER(ALL(‘Date’),

                          ‘Date'[Calendar Year] = MAX(‘Date'[Calendar Year]) &&

                          ‘Date'[Date] <= MAX(‘Date'[Date])))

Compare the result TOTALYTD() with our script.

Explaining the script.

Let us consider that we are in row 2014 – March row on the above table.

YTDSales = CALCULATE([Total Sales],

FILTER(ALL(‘Date’),

‘Date'[Calendar Year] = MAX(‘Date'[Calendar Year]) &&

‘Date'[Date] <= MAX(‘Date'[Date])))

 

‘Date'[Date] <= MAX(‘Date'[Date]) => This line of code returns maximum date. In our case, It will return 31/3/2014

‘Date'[Calendar Year] = MAX(‘Date'[Calendar Year]) => This line of code returns maximum year.  In our case, it will return 2014

ALL(‘Date’) => This line of code returns all the dates from date table.

FILTER(ALL(‘Date’),

‘Date'[Calendar Year] = MAX(‘Date'[Calendar Year]) &&

‘Date'[Date] <= MAX(‘Date'[Date])))

The above line of codes returns, current row year and last date of the current row month.

 

ByHariharan Rajendran

Connect Live option disabled

This post solves the very simple problem in Power BI.

If you are trying to access the Power BI datasets to create reports then you may encounter this below error message.

Error: “The connect live option for this file is disabled because it already contains data from another data source.”

“Power BI datasets” is one of the options from “Get Data”.  Whenever you publish a report from Power BI desktop to Power BI services, it is publishing the dataset and report.

You can create multiple reports using the same published datasets from Power BI services. This is something like a shared dataset. In case, if you are experiencing the above error then you need to ask your administrators to fix the issues.

The administrator has to fix this issue on the admin side of the Power BI services. Follow the below steps.

  1. Go Power BI cloud services
  2. Go to the Admin portal
  3. Click Tenant settings on the left side and check the export and sharing settings
  4. Enable the export data feature.

That’s it. The issue has been fixed.

ByHariharan Rajendran

Anybody can use R visuals in Power BI

This post explains that anyone can get R visuals for their data with ggplot2.

Power BI is very famous for different types of visualizations right from out of the box visualizations, R visualizations and custom visualizations.

To generate R visuals, you need to write R codes on the editor window. It is possible when you have a basic knowledge of R packages. Microsoft makes this process easy and provided many R custom visuals which is like other visuals where you can drag and drop the fields on the respective axis.

R custom visuals doesn’t require R codes.

Another option that you can easily create R visuals using ggplot2 builder without writing much code.

Esquisse is a small add-in to R studio helps you to interactively explore your data by visualizing it with the ggplot2 package. It allows you to draw bar graphs, curves, scatter plots, histograms, then export the graph or retrieves the code generating the graph.

Refer the below URL,

https://github.com/dreamRs/esquisse

Follow the below steps to use this on your Power BI Desktop.

You need to have R studio installed on your machine

Install the devtools using below command.

install.packages(“devtools”)

Install the “dreamRs/esquisse” using below line of code

devtools::install_github(“dreamRs/esquisse”)

install.packages(“ggplot2”)

You need to perform the above steps in the R studio.

Once above steps are performed then you are good to go with Power BI Desktop.

You can take any dataset which you want to use it for R visuals. Try to have different columns like date, number string to experience all the visuals from ggplot2.

Add the R visual into the canvas area and it will open the editor below. To add a R script, you need to choose the fields from your dataset.

When you added the fields, you can see the R editor enabled to write codes.

Copy and paste the below line of code and click the run button.

esquisse:::esquisser()

It will open your browser and load the ggplot2 builder.

It will look like below.

First, you need to choose the dataset from the drop down of the data.frame list.

It will show all the columns as variables. You need to select all or whichever you want to use it for your visuals. Then finally choose the selected variables will be added.

On the Left top, you can see “auto”, you can click and see what are the visuals are supported as of now.

Next, you need to drag and drop the variables on respective sections. The sections are,

X Axis

Y Axis

Fill

Color

Size

Based on the data type you can choose different visuals. Sometimes few visual will not be enabled, if that is the case then your data is supported for those visuals.

To customize the visual, you can use the bottom bar options.

Label & Title

Plot Options

Data – Filter

Once you satisfied with the visual then you can copy the generated code and paste it on the R editor in Power Bi Desktop.

Before running the script, you need to comment on the previously added line of script and add the below line of code.

Library (ggplot2)

Then run the script.

It will generate the R visual on your report.

Thanks. Let me know if you have any doubts. Reach me on hari@yoursqlman.com.

ByHariharan Rajendran

DAX – RELATED & RELATEDTABLE

This post explains the concept of below DAX functions

  1. RELATED
  2. RELATEDTABLE

I need to explain the data modelling little bit before going to DAX functions. As you know, we need to create a relationship either manually or automatically to use the tables together to get the expected result.

We have 3 different relationships available.

  1. One-to-One Relationship
  2. One-to-Many Relationship
  3. Many-to-Many Relationship

In the context, let us consider a one-to-many relationship. If you have CUSTOMER master and FACT tables then trying to create a relationship, then that would create a one-to-many relationship.

It means we have unique records on the customer table but multiple same values on the FACT table with reference to the connected columns.

If you want to create a new calculated column on the CUSTOMER table then you need to use RELATEDTABLE DAX function. On the other hand, when you want to create a calculated column on the FACT table then you need to use the RELATED function.

RELATEDTABLE:

Customer First Purchase = MINX(
RELATEDTABLE(‘Sale’),
‘Sale'[Invoice Date Key])

 

RELATED:

State = RELATED(‘City'[State Province])

ByHariharan Rajendran

[Solved] Microsoft Access: The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine

This post helps you solve the below issue in Power BI.

Scenario: There will be an error when we connect with 32-bit Access Database from Power BI 64-bit desktop.

Error: “Microsoft Access: The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine”.

Solution

To solve the above issue, follow the below steps.

  1. Visit https://www.microsoft.com/en-gb/download/details.aspx?id=13255
  2. Download 64-bit version of the software.
  3. Install on the machine where Power BI is installed.

Once completed the above steps, try to connect access DB from Power BI desktop. This time you will be able to connect without an issue.

Post your comments if you get any more issues in this scenario.

ByHariharan Rajendran

Don’t use boring default tooltips in Power BI

Power BI recently announced a new feature to customize the tooltips. This post explains the steps to create a customized tooltip to improve your analytics.

As you know, tooltips are an important feature of every business intelligence project. It helps end user to understand the values when they mouse hover on any visuals on the report.

Traditionally, it will give us the very minimal version of the information. Microsoft has extended this feature to create analytics even on mouse over. Yes, can create a simple report and can integrate that report on your visuals. It means, when end user mouse hover on the visuals, it will show your customized tooltip report.

It is a preview feature now, so you need to enable this feature on Options->Preview Features

Follow the below steps

  1. Create a new page on your Power BI Report
  2. Go to Format option of the page and expand the Page Size option. There you can set the type as “Tooltip”
  3. Set the Page view as “Actual Size”
  4. You can see the small canvas area where you can create a simple report with different visuals.
  5. Go to Main report page where you want to integrate the customized tooltip. Make sure that you enabled the preview feature.
  6. Choose the visual and go to Format option and you could see an option called “Tooltip”. Extend the option.
  7. Under Page option, choose the created tooltip page. That’s it.
  8. Mouse hover the visual and you could see the customized tooltip.

Screenshots.

 

ByHariharan Rajendran

CData SharePoint SSIS Components

I had a requirement to extract the data from SharePoint (only Metadata) and I was looking for a task to handle this in SSIS.

Then I found a simple 3rd party plugin to fulfil my requirement. In this post, I am explaining how to use the CData SSIS components.

You can download the component from https://www.cdata.com/drivers/sharepoint/ssis/.

The above link will take you directly to the download page. You need to buy this tool to use it on your production packages. If you want to test, then you can go with a trial version.

Download and install where you installed the SQL Server Data tools.

Once you installed then you can start creating an SSIS package using CData SharePoint Source and Destination tasks.

You need to create a connection manager to speak with on your SharePoint server either on-premises or online.

Right click on the connection manager section and choose “CDATA_SHAREPOINT”.

You need to enter your SharePoint site URL and credentials.

Once everything is done then drag and drop the “CData SharePoint Source” task. Point the created Connection manager. Under Table or View, you can choose any of the resources from SharePoint.

Check the columns and ensure everything is working. Then you can map the output to the destination tasks.