Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
256 views

What Is M, Power Query and DAX?

M is a query language used to import and transform data in Power Query. DAX is the formula language used to analyze and calculate measures in Power BI data models. MDX is a query language for multidimensional cubes, used before data import in Power BI. These languages have different purposes - M for data import and cleaning, DAX for post-import calculations, and MDX for pre-import cube querying.

Uploaded by

jashu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
256 views

What Is M, Power Query and DAX?

M is a query language used to import and transform data in Power Query. DAX is the formula language used to analyze and calculate measures in Power BI data models. MDX is a query language for multidimensional cubes, used before data import in Power BI. These languages have different purposes - M for data import and cleaning, DAX for post-import calculations, and MDX for pre-import cube querying.

Uploaded by

jashu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

By Harsha

what is M, Power Query and DAX?


M is used in Power Query (a.k.a. Get & Transform in Excel 2016) and the query tool for Power BI
Desktop. Its functions and syntax are very different from Excel worksheet functions. M is a mashup
query language used to query a multitude of data sources. It contains commands to transform data and
can return the results of the query and transformations to either an Excel table or the Excel or Power BI
data model.
M is used during your data import.
Use M to transform and cleanup your data as well as create custom columns during data import.

The Power Query Formula Language is a powerful query language optimized for building queries that
mashup data. It's a functional, case sensitive language similar to F#, which can be used with Power
Query in Excel, Get & Transform in Excel 2016, and Power BI Desktop.

DAX stands for Data Analysis expressions. DAX is the formula language used in Power Pivot and Power BI
Desktop. DAX uses functions to work on data that is stored in tables. Some DAX functions are identical
to Excel worksheet functions, but DAX has many more functions to summarize, slice and dice complex
data scenarios. DAX is also found in other offerings from Microsoft, such as Power Pivot and SSAS
Tabular.
DAX is used after your data has been imported into your data model.
Use DAX to create Custom Columns and Measures within a data model.

MDX

What
Multi-Dimensional Expressions (MDX) is the standard language defined by Microsoft to query
multidimensional cubes, such as those created with Microsoft SQL Server Analysis Services. MDX might
at first appear to be similar to SQL, however, MDX is a completely different language. Whereas SQL was
designed to query relational databases composed of tables where data is organized in terms of columns
and rows, MDX was designed to query OLAP cubes where data is organized in terms of measures,
dimensions, hierarchies, and levels.

When
MDX is used before your data import.

Where
MDX is used when querying SQL Server Analysis Services (SSAS), Excel when connecting to
multidimensional cubes and in Power BI Designer. In Power BI Designer, you can use MDX when using a
data source connector for a multidimensional cube such SSAS. Similar to how to use SQL above, from
within the connector interface, choose "Advanced Options" and there will be an optional area into
which you can paste MDX code.

Why
Use SQL to pre-filter and join your data before you start working with it. It will generally be more
efficient to perform a complex join or selection of columns using MDX versus in M or within the data
model.

How
To learn more about MDX, see Microsoft's Multidimensional Data Access documentation

By Harsha
By Harsha
Difficulty
3 - MDX is more difficult to wrap your head around than SQL and is somewhat of a unique language as
far as languages go.

DAX
Data Analysis Expression. We have following different DAX functions in Power BI.
 Date and Time
 Filter Functions
 Information Functions
 Logical Functions
 Mathematical and Trigonometric Functions
 Statistical Functions
 Text Functions
 Time Intelligence Functions

DAX Operators and Constants


 () Parenthesis
 + addition
 - subtraction
 * multiplication
 / division
 ^ exponential
 + equal to
 > greater than
 >= greater than or equal to
 < less than
 <= less than or equal to
 & Concatenation
 && and
 || or

Text Functions
BLANK: using blank function, we can replace the specific values with the blanks.
Ex: IF(SUM('Filters'[Sale]) = 100, BLANK(), SUM('Filters'[Sale])), this formula will replace 100 with the
blank.
‘Filters’ is a Table, [Sales] is a field in the table.

Note: Blanks are not equal to null.

CONCATENATE: to combine or joins two text strings into one text string. The joined items can be text,
numbers or Boolean values represented as text, or a combination of those items.
Ex: create a new column, CONCATENATE(Naani&" ", Haksha) (&” “ is to get the delimiter space)

By Harsha
By Harsha
Note: it accepts only 2 arguments (Ex: concatenate(“Naani” , “Haksha”), it accepts 255 arguments in Excel.

EXACT: compares 2 string and returns true or false, if they are same then returns true, if not returns
false.
Ex: New Columns, Exact(Haksha, Haksha) = True
Exact(Haksha, Asha) = False

FIND: will find the position of the first letter of the given string
Ex: find(“k”, “Haksha”) = 3

FIXED: will round the values, works on numeric fields.


Ex: fixed(567890.5879, 2) = 567,890

FORMAT: converts value into string as you specified format.


Ex: FORMAT ( 12345.67, "General Number"), 12345.67 "General Number" displays the number with no
formatting.
FORMAT ( 12345.67, "Currency"), $12,345.67 "Currency" displays the number with your currency locale
formatting. The sample here shows the default United States currency formatting.
FORMAT ( 12345.67, "Fixed"), 12345.67 "Fixed" displays at least one digit to the left of the decimal
separator and two digits to the right of the decimal separator.

SUBSTITUDE: will replace the taken string with the given conditions.
Ex: create a new column, SUBSTITUDE([Harsha], “rsha”, “ksha”) = Haksha

REPLACE: will replace the characters from the beginning of the taken field.
Ex: REPLACE (“NaaniHarsha”, 1, 5, “Haksa”) = HaksaHarsha
Note: “NaaniHarsha” is taken string, 1 is starting character in the NaaniHaksa, 5 is it will replace 5
characters from starting character (N to i) (Naani will get replace with Haksa)
Note2: also we can replace 5 characters with less than 5 or more than 5.

REPT: it will repeat the give text values in the new column.
Ex: REPT(“Harsha”, 2) = HarshaHarsha

Filter Functions
ADDMISSINGITEMS:

CALCULATE: Calculate is only the single functions in DAX which is able to modify the filter context.
returns true if the conditions satisfy, if not returns false.
Ex: calculate(sum(Sales) > 1000) = Returns true if the value is more than 1000 else false.
Ex2: CALCULATE(SUM(Orders[Sales]), Orders[Sales] > 120000), returns the values which are more than
120000.
Ex3: CALCULATE(SUM(Orders[Sales]), Orders[State] = "Arizona"), it will return Arizona state values to all
the states.

By Harsha
By Harsha
Scenario: want to develop a report, Ex 1 transaction value is 1000, profit is 200 from that transaction,
like that, want to see all the transactions values, which are giving more 100 profit. For all the states
1. Create a table, select state, Sales and profit.
2. Create a new measure, name it as Sales value from more than 100 profit, write the following
formula,
CALCULATE(SUM(Orders[Sales]), FILTER(ALL(Orders[Profit]), Orders[Profit] > 100))
3. It will show the state wise sales values. Which are giving more than 100 profit.

ALL: returns all the rows in the table or a column, it will ignore all the filters at Visual level.

CALCULATE (SUMX (Orders, Orders[Sales]), ALL(Orders[State]))

Logical Functions

SWITCH: evaluates an expression against a list of values and returns one of multiple result expressions.
Ex: Create a new column,
SWITCH(Orders[Region],
“South”, “PST”,
“East”, “EST”,
“Central”, “CST”,
“West”, “MST”,
Orders[Region])

Note: all the result expression and else expression must be same data types, it will not allow multiple
data types in the formula.

Numeric Functions

DIVIDE: perform division and returns alternate result


Ex: DIVIDE (101, 111) = 0.91

Note: handing the nulls and blanks in divide function, we can use zero, EX: DIVIDE (Sum(Actual),
SUM(Target), 0) it replaces with the 0.
Note2: need to use an aggregation function, when we use DIVIDE, if the column is not an aggregated.

Difference Between SUM and SUMX?


SUM: will work on only one column
Ex: Sum(Sales)

SUMX: will work on two fields, 'A' is a table name. to make use SUMX, first we need to take the table
name in the DAX formula.
Ex: SUMX ('A', 'A'[Price]*'A'[Quantity])

By Harsha
By Harsha
Number.RoundDown: returns highest integer less than or equal to number value
Ex: Number.RoundDown(25.278) = 25
Ex2: Number.Round.Down(-25.678) = -26

Date and Time DAX functions


Calendar: using calendar function we can generate the dates,
1. Click on the modeling tab, select new table, it will open the DAX formula tab, Name it as a Date,
write the following formula,
CALENDAR ("1/1/2016", "12/31/2017")
2. It will create a new table with the field called Date with date ranges from 1/1/2016 to
12/31/2017.
3. Select the data from the left navigation to see the data.

How to get rank based on the value?


1. Using Super store data, create a table using State and Sales.
2. Create a new column, name it as Rank, write the following formula,
Rank =

Power BI components or Building blocks

Following are the Power BI components;


 Visualizations or Tiles
 Datasets
 Pages or Dashboards
 Report

Visualizations or Tiles: visualization is a visual represent of the data or a smallest developed objective in
the Power BI or a single visualization in a Page (Ex: Bar chart, Pie chart, Doughnut)

Datasets: is a collection of data that Power BI used to created or uses to create visualization for analysis.
Like SQL Server, MySQL, Oracle, salesforce, Hadoop.

Pages or Dashboards: collection of Visualizations or Tiles. Or a single layer representation of multiple


visualizations.

Reports: is a collection of Pages or Dashboards.

Parameters

Measures Parameter Creation

By Harsha
By Harsha
1. Click on Enter Data from the Home menu bar, it will open the Create Table window, Rename the
Column1 as Measures Parameter, create 2nd column name it as Index.
2. Under the Measures Parameter column enter the required measure names, Sales, Profit and
Quantity, In the Index column give the 1, 2 and 3.
Note: Index is to get variables in sequence, If we assign 1 to Sales, in the list Sales is going be on top.
3. Bottom of the Create Table window, change the Table name Table 1 to Parameters, click on
load.
4. Now, we can see a new table with 2 columns which we have created in 1st step.
5. We need to create 3 new measures to get Sales, Profit and Quantity variables. To create a new
measure, click on the New Measure from Home menu and select New Measure, name it as Dyn
Sales, write the following formula, = SUM(Orders[Sales])
6. Repeat the same for Profit and Quantity.
7. Create a new measure field to assign sales, Profit and Quantity to Parameter, name it as
Dynamic Measures and write the following formula,
(SWITCH(TRUE(),
VALUES('Measures Parameter'[Dyn Measure]) = "Sales", [Dyn Sales],
VALUES('Measures Parameter'[Dyn Measure]) = "Profit", [Dyn Profit],
VALUES('Measures Parameter'[Dyn Measure]) = "Quantity", [Dyn Quantity],
0)
8. select clustered bar chart from the visualization and select State, Dynamic Measure measure filed,
select filter from the visualization and drop Measure Parameter into the filter.

How to get the %N Sales increase?


1. Click on Get Data, select Blank Query, write the following query
={0..100}
2. Right click on list select To Table.
3. Under the Query Settings, change the name to Parameter from Query.
4. Click on Home, select apply & close.
We can see a new table with the name Parameter.
5. Select Parameter field, click on modelling in the menu bar, change the data type to whole
number.
6. Create a new measure, write the following formula,
Sales N% Increase = SUM(Orders[Sales])*SUM(Parameter[Parameter])/100 +
SUM(Orders[Sales])
Note: Orders table, Parameters is newly created table by making use of Blank query (Power Query)
7. Select Clustered bar chart from the list of the visualization, select Region and Sales N% Increase
fields.
8. Select slicer from the list of visualizations, select Parameter field from the Parameter table.
9. From the list of the numbers, select the required number to see the percentage of the select
number.

Ranking / Index

By Harsha
By Harsha
Below is the table, table name is Project Comp.

Requirement is to get latest Submitted Date by Emp ID wise and Project wise. Ex: 101, FnA, 9/7/2016
6:20:25 PM is the latest Submitted date for Emp no 101 for FnA Project.

Follow the below steps to get the require output.


First check the Data type of Emp ID, convert to string, if it is a Numeric.
1. Click on Modelling tab, select create table. (To create a new table)
2. It will open a DAX formula tab (It will create a new table), name it as Rank, write the following
formula,

Rank = SUMMARIZE('Project Comp', 'Project Comp'[Emp ID], 'Project Comp'[Project], "Date",


MAX('Project Comp'[Submitted Date])

3. Hit enter, it will create a new table, select a table visualization, select Emp ID, Project, Date from
the newly create table. Below is the results, it will give.

By Harsha
By Harsha

Note: Rank is a Name of the new table, SUMMARIZE is function, ‘Project Comp’ is table name.
Note2: we should not use any interval, when you want find out the max date from the date field.

Moving calculated fields from one table to another table


1. Select the required calculated field, Click on the Modelling in the Menu bar.
2. Next to the Home Table, click on the drop down, it shows the list of tables, select the required
table from the list.

KPI’s creation
1. Select new measure, name it as KPI, write the following formula
Switch(true(),
sum(Sales) < 15000, “High”,
sum(Sales) < 10000, “Medium”,
sum(Sales) < 5000, “Low”,
“Very High”)
2. Select table from the list of visualization, select customer, KPI calculated field, Sales.
Note: we need to write the formula in the hierarchy mode from highest value to lowest value.

Dates

Formula example for Intervals


Year = year([Date]), year is function and returns year and [Date] is a date field.
Ex: year ([1/25/2016]) = 2016

Month = month([Date]), month is a function to return month. It returns the month number
Ex: month ([1/25/2016]) = 1

Quarter = INT([month] +2)/3, we need to derive the month from the date field to get the quarter. INT
function is to return the date value as an integer.
Ex: INT ([1/25/2016] +2) / 3 = 1 (1st quarter)

Month Name = format([Date], “mmmm”), format will give you the given interval name, “mmmm” to get
the month name, if we want month abbreviation use “MMM”
Ex: format ([1/25/2016], “mmmm”) = ‘January’

By Harsha
By Harsha
Day of week = format([Date], “ddd”)
Ex: format ([1/25/2016], “ddd”) = “Mon”

Week = we don’t have any function, which derives the week from the date field, we need to create 2
new columns, one is to find the day of week and another one to find out the position of the day in the
data set, write a formula that returns values from the date field as an integer.
INT ([Date])
Then we need to find out the first Sunday in the data set. Then write the following formula to write
extract the week number, write the following.
INT = ([Date] - 200) / 7
Note: here Date is a Date field, 200 is the position of the first Sunday in the data set, then dividing it with
the 7 (days in a week)

DAY: it returns the day of the taken date fields, a number from 1 to 31.
Ex: create a new column, DAY (“September 25, 2017”) = 25
Ex2: IF (DAY([Order Date]) = 25, “Hakshaya”, “ “), it returns “Hakshaya”, the day each order date is 25 of
any month.

DATE: it returns the specified date in the datetime format.


Ex: Create a new column, DATE (2017, 09, 25) = September 25, 2017
Note: Year number represents year, Month number represents month, day number represents Day.
DATEVALUE: it converts text date to datetime format. It uses local system date and time.
Ex: Create a new column, DATEVALUE("9/25/2017") = 9/25/2017 12:00:00 AM

HOUR: it will return hour as a number from 0 to 23, it will take the input as time (time stamp)
Ex: create a new column, HOUT(“September 25, 2017 7:00 PM”) = 19

CALENDER: we can return a table with a single column with range of dates, the range of dates is from
specified start and end date.
We can’t use Calendar function as normal DAX functions,
To use calendar or to generate range of dates, follow the below steps
1. Click on modelling tab, select new table, it will open a new formula tab,
2. Write the following formula, CALENDAR (“1/1/2017”, “1/1/2020”), hit enter
it will generate a table with a field called Date, that contains the dates range from 1/1/2017 to
1/1/2020.

EDATE: it returns the date that’s is indicated number of months based on the taken date.
Ex: Create a new column, EDATE (“September 25, 2017”, 1) = October 25, 2017
Ex2: EDATE (“September 25, 2017”, 2) = November 25, 2017
It will add given number of months to the taken date.
We use EMONTH and EOMONTH functions mostly in the insurance domain to calculate maturity dates
and in all the domains where we need to find the Amount due date or to define the payment terms.

EOMONTH (End of Month: it returns the date in the format of datetime.


Ex: Create a new column, EOMONTH (“September 25, 2017”, 0) = September 30, 2017
Ex2: EOMONTH (“September 25, 2017”, 1) = October 31, 2017

By Harsha
By Harsha
Note: Ex2 returns October 31, 2017, because the month’s argument is 1. It will add 1 month to
September.
Note2: if the date is not in the date format then EOMONTH through an error. To avoid unexpected
results, convert the string or number fields to date.

Date difference
1. Select create new column, name it as Days Difference, write the following formula
DATEDIFF(Orders[Order Date], Orders[Ship Date], day)
2. Select table from the list of visualizations, select customer name, order date, ship date and Days
diff calculated filed.
Note: date shows in the hierarchy mode, if we want get exact date, under Values, click on the Order
date drop down and Order data instead of Date hierarchy.
It shows weekday name, month name and year. If we want I numbers, select the order date in the table,
click on the modeling in the menu bar, from the list of format, select the required format.

How to get the last 7 Days sales?


1. Create a new Column, Name it as Rank, write the following formula to get the rank
RANKX (Orders, Orders[Order Date])
2. Select table, select date field, create a new measure, write the following formula
CALCULATE(SUM([Sales]), Sheet1[RANK] <= 7, ALL(Orders[Order Date].[Date]))
How to get recent Date sales?
1. Select a new column to get the last date, write the following formula
Max(Orders[Order Date]) {we should not take any date part)
2. Select a new measure from the ribbon, write the following formula
IF (Orders[Order Date] = MAX(Orders[Order Date], SUM([Sales]))

How to get Last year YTD?


1. Create a new measure, name it as LY YTD, write the following formula
Calculate(YTD, SAMEPERIODLASTYEAR(Orders[Order Date].[Date])
Note: YTD is the calculation which we have create to get YTD, SAMEPERIODLASTYEAR is a function.

How to calculate difference from previous month?


1. Connect to Sales Data, select table, select order data and sales.
2. In fields, under the values, unselect Day and Quarter, now the view shows year, month wise
sales.
3. Write the following formula to get the difference, select New measure, name it as Difference,
SUM(Orders[Sales]) - CALCULATE(SUM(Orders[Sales]), PREVIOUSMONTH(Orders[Order
Date].[Date]))

OR

SUM(Orders[Sales]) - CALCULATE(SUM(Orders[Sales]), PARALLELPERIOD(Orders[Order


Date].[Date], -1, MONTH))
Note: in the view, we shouldn’t take the data at day level, if we take, DAX will not work, because we are
trying to find the difference at month level.

By Harsha
By Harsha
Day Level difference
SUM(Orders[Sales]) - CALCULATE(SUM(Orders[Sales]), PREVIOUSDAY(Orders[Order Date].[Date]))

Previous year sales difference


1. Create a new measure, Name as Difference in Sales, write the following formula
Difference = SUM(Orders[Sales]) - CALCULATE(SUM(Orders[Sales]),
PARALLELPERIOD(Orders[Order Date].[Date], -1, YEAR)).
2. Select the clustered Column chart from the list of the visualizations, select year, sales and
Difference in Sales fields.

How to extract month name from the order date or date field?
1. Create new column name it as Month, write the below power query
Orders[Order Date].[Month]
Note: Orders is tables name, Order Date is Date field, . (Dot) Month is the functions, which helps to
derive the month name.

How to extract the year from the field?


1. Create a new column, name is as Year, write the following formula,
Year = Orders[Order Date].[Year]
2. Select the Year field, which created in 1st step, click on modelling, from the list of Default
Summarization, select DO Not Summarize.
3. Select table from the list of visualizations, select year field to see the years.

How to sort the Month in month order?


1. Create a new column, name it as Month Rank, write the below query
Orders[Order Date].[MonthNo]
Note: Orders is tables name, Order Date is Date field, . (Dot) MonthNo is the functions, which helps to
derive the month number.
2. Select the Month field (which we want to sort) from the field list, click on the modelling tab in
the menu bar, click on sort by column and select Month Rank field.
3. Click on the Matrix table in the visualization and select Month field to check either it’s in the
required order not.

How to generate the Dates?


4. Click on the modeling tab, select new table, it will open the DAX formula tab, Name it as a Date,
write the following formula,
CALENDAR("1/1/2016", "12/31/2017")
5. It will create a new table with the field called Date with date ranges from 1/1/2016 to
12/31/2017.
6. Select the data from the left navigation to see the data.

How to extract the Month and Year from the date field?
1. Create a new a column, name it as Mon & Year, write the following formula
FORMAT('Date'[Date].[Date],"MMM") &" "& FORMAT('Date'[Date].[Date], "YY")
Note: Format is DAX function, ‘Date’ is table name, [Date].[Date] is a filed name which is coming for the
Date table, “MMM” is syntax to get month name, “YY” is to get Year.

By Harsha
By Harsha
How to find the recent transaction of every customer?
1. Create a new column, name is=t as Max Date, write the following formula
CALCULATE(MAX(Orders[Order Date]), FILTER(Orders,[Customer
Name]=EARLIER(Orders[Customer Name])))
Note: Orders is your table, Filter will perform on the customer Name field by taking which customers
comes from the Earlier. (Earlier is DAX function), it will give the output by performing group by on
Customer Name and the recent date.
2. Select table from the visualization, select Customer Name and Max Date to see the recent
transaction data.
3. We can also represent old transitions as Old Transaction, Recent one as New, for the create a
New column, Name is as Is Recent, write the following DAX,
= IF(Orders[Order Date] = Orders[Max Date], "Recent", "Late")
4. Select new table, select customer name, order date and Is Recent. To see the results.

How to get 2013 sales using calculation?


1. Create a new measure, name it as 2013 sales, write the following formula
CALCULATE(SUM(Orders[Sales]), FILTER(Orders,Orders[Order Date].[Year] = 2013))
Note: Filter will filter the years, Orders is Table, Orders[Order Date] shows table name and field name,
Year to get Year (2013), 2013 is required year.

UNICODE / KPI with shapes


Find the state wise difference between 2012 and 2013 Sales, if 2013 sales more than 2012 then show
it with up arrow else down arrow (Triangle)
1. Create a new measure to find the 2012 sales, name it as 2012 sales, write the following formula
CALCULATE(SUM(Orders[Sales]), FILTER(Orders, Orders[Order Date].[Year] = 2012))
2. Create a new measure to find the 2013 sales, name it as 2013 sales, write the following formula
CALCULATE(SUM(Orders[Sales]), FILTER(Orders, Orders[Order Date].[Year] = 2013))
3. Create a new measure to find the difference between 2012 Sales and 2013 Sales, name it as Diff
b/w 2012 & 13, write following formula
[2013 Sales] - [2012 Sales]
4. Create a new measure to get the up and down arrows based on the values, name is as KPI, write
the following formula
IF([Diff b/w 2012 & 13] > 0, UNICHAR(9650), UNICHAR(9660))
5. Select Table, select state field, 2012 Sales, 2013 Sales field, b/w 2012 & 13 and KPI
Wherever the 2013 Sales are more than 2012 Sales, it shows with the up arrow else with down arrow.

Note: to find the Unicode for difference arrows and icons refer http://unicodelookup.com/#triangle/1
Note2: with the help of UNICODE we can get the up and down arrows. 9650 is to get up arrow and 9660
is to get down arrow.

How to get YTD?


1. Create a new measure, name it as YTD Sales, write the following formula,
TotalYTD(sum(Orders[Sales]), Orders[Order Date].[Date])
Note: TotalYTD is a function, which will derive the year to date data. Date is function.

By Harsha
By Harsha
How to get Central Region Profit using calculations?
1. Create a new measure, name it as Central Region Profit, write the following formula,
CALCULATE(SUM(Orders[Profit]), FILTER(Orders, Orders[Region] = "Central"))

Data cleaning and Transformation

How to extract Year, Quarter, Month and day from the date field?
1. Right click on the table from the fields, select edit query.
2. Select the required table under the Queries.
3. Select the field, from which field we need to extract the date parts, select the Order date (just
select the field)
4. Click on Add Column in the menu bar, under the Date, click on the drop down, in list we can see
all the date parts, select the required date parts. It will create a new column with the selected
interval name at the end of the table.

First Name and Last Name


First name = LEFT(SUBSTITUTE(Table1[Name]," ","-"),SEARCH("-",SUBSTITUTE(Table1[Name]," ","-"))-1)

Last name = RIGHT(SUBSTITUTE(Table1[Name]," ","-"),LEN(SUBSTITUTE(Table1[Name]," ","-"))-


SEARCH("-",SUBSTITUTE(Table1[Name]," ","-")))

How to combine 2 fields?


1. Click on modelling tab, click on new column, name it as Concatenation, write the following
formula
‘Orders’[City] & “, “ & ‘Orders’[State]

Grouping
1. Right click on the region field and select new group, it will open a create group window.
2. Give a name to group as region group, (in the field box, we can on which field we are creating a
group), under the Ungrouped values, select the required regions to be grouped, select Central,
East and South, click on the Group.
3. Selected regions will move to the Group and members box. Give it a required name as 3 regions.

By Harsha
By Harsha
4. Now, we can see central, east and south in 3 regions group, if we select Include Other group,
West region will appear as Others, if we don’t select Include Other group west will be shows as
west.

Handling the nulls?


= if [NewColumn.State] = null then [State Name] else [NewColumn.State]

if [State Name] = "WASHINGTON, D. C." then "DC" else if[NewColumn.State] = null then [State Name]
else [NewColumn.State]

=if [State2] = 0 then [State Name] else [State2]

=if [State Name] = "WASHINGTON, D. C." then "DC" else if[State2] = 0 then [State Name] else [State2]

Joins
What is flattening?
A. Some BI products require you to collapse two or multiple tables into a single table before
loading into the product, this is called flattening.

Note: But in Power BI most of the time it automatically figure out the relationship between the tables
you bring in. it will find the relationship either at the time you load the tables into the model or the time
you go to use them. However there will some cases where we can’t find the relationship and in those
cases you will need to create the relationship manually.
Note: when we connect to any flat file, Power BI might not detect the relationship automatically.

If you want to perform it manually, follow the below steps.


I have 2 different below tables,

Dept ID Table

Dept Details Table

By Harsha
By Harsha

1. Connect to these tables, Dept Table headers showing as Column 1 and column 2, to change it to
the actual field name, Right click on the Dept ID table, select Edit Query, in the Menu Bar, from
the List of Home, click on Use First Row as Header drop down, select Use First Row as Header.
Click on close & Apply.

Here, we have to show Project wise Hours in the Reports (we have to take Project field form the Dept ID,
the field name is Working On)
2. Select Table from the visualization, select Working On field filed from Dept ID table and Hours
from the Dept Details table.
If we validate the data, the results are not matching with the data. Hours are same for all the projects,
it’s due to the joining condition. Here Joining didn’t performe. We need to perform the joining manually.
To do that follow the below step.
3. Click on the Home in the menu bar, click on the Edit relationship, it will open the Manage
Relationship window.

By Harsha
By Harsha

4. Click on New in the Manage relationship window in the bottom, then it will open the Create
Relationship window. Select Dept ID Table from under the list of select tables and columns that
relate to one other.

5. Select the Dept Details from the list in the 2nd table pane,

filters

In Power BI we can perform the filtering at 3 levels.


1. Visual level filter, 2. Page level filter, 3. Report level filters.
Visual level filter: works on only individual visualization.
Page level filter: works at the report level. It means its going to perform the filtering on all the
visualizations which are used in that page.
Report level filter: works at the entire report. Means it’s going to perform the filtering at all the pages
and the visualizations.

How to deselect the not required fields?


1. Connect to the super store data, connect to Orders table.
2. Right click on the Orders table under the fields, select Edit Query. Power BI will open the Edit
Query window.

By Harsha
By Harsha
3. Under the queries select the Orders table.

4. From Home ribben, click on choose columns, it will open a choose columns window with all the
available fields in the select data set, just unselect the fields which are not required. Click on ok.

5. Click on apply and ok, check the fields either it’s unselect or not.
Note: we can achieve the same by making use of the Remove columns also but using Remove columns,
we need to select the not required field and select Remove columns.
In remove columns we have 2 options, Remove columns option will remove the selected column and
Remove other columns option will remove all the fields which are not selected.

Note: if you want to get back the unselected fields,


1. Right click on the data set, in which data we have excluded the fields, select edit query option.
2. Select the data set from the list of the data sets under the queries, under the Query setting,
under the Applied Steps, we can find the Removed Others Columns, click on the setting icon, it
will open the choose columns window, from the list we can select the required fields.

By Harsha
By Harsha

By Harsha

You might also like