Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

POWETR BI

What is the use of creating groups in PowerBI


What is DAX in power BI ?
These are library of function and operations that can be combine to form formulas and
expression.
Used to create calculated measures and column that will enhance the dashboard.

Use of sumx
CALCULATE(SUMX(TABLE_NAME,EXPRESSION)

example
Measure = CALCULATE(DISTINCTCOUNT(Orders[Order
ID]),FILTER(Orders,Orders[Region]="central"))
Measure 3 = CALCULATE(SUM(Orders[Sales]),Orders,Orders[Sub-Category]="machines")

We can use calculate table to create another table


sales22 = SUMX(CALCULATETABLE(Orders,Orders[Category]="Technology"),Orders[Sales]
)

top_N_sales = calculatetable(Orders,TOPN(10,Orders,Orders[Sales]))
Use ASC for bottom and DESC for top profit or sales

To get the rank of the sales


rank_sales = RANKX(Orders,Orders[Sales],,DESC,Dense)
Instead of dense one can use Skip, it will skip the values is there is a repetition

AVG DELIVERY =
DATEDIFF(Sheet1[Order Date].[Date],Sheet1[Ship Date].[Date],DAY)

This formula is used to get average delivery date between two dates one is order date and other is ship date.

For the below you have to create the table in power BI


salesforcast =
SUMMARIZE('Sheet1','Sheet1'[Order Date],"total
sales",SUM('Sheet1'[Sales]))
This formula is uses to give unique dates if they are repeating and sales of
repeated dates get summarized. This is used for forcasting

This is used to assign rages


sales(switch) =
SWITCH(
TRUE(),
Orders[Profit]>=0 && Orders[Profit]<100,"0-100",
Orders[Profit]>=100 && Orders[Profit]<500,"100-500"
,"500+"
)

sales(switch) =
SWITCH(TRUE(),
Orders[Sales]<=100,"bad",
Orders[Sales]<=500,"good","great")

CHECK IF CONDITION = IF(Orders[Sales]>1000 ,"GOOD","NOT SATISFIED")

To check the no day taken to deliver the produt


delivey_days = DATEDIFF(Orders[Order Date],Orders[Ship
Date],DAY)

This goes row by row

Total Revenue = SUMX(Sales, Sales[Quantity] * Sales[Price])

IsBlankFlag =
IF(ISBLANK(YourTable[Column]), "Blank", "Not Blank")

blank = isblank(Orders[Postal Code])

This is use to get a increment in the month or to sift to ther next month
Column = DATEADD(Orders[Order Date].[Date],31,DAY)
Example 6 jan 2023 change to 6 feb 2023

3:
SALES =MRP-DISCOUNT

MRP =200
DISCOUNT=20%

Sales =200-40=60
sales=mrp-mrp*discount
=mrp(1-discount)
mrp=sales/(1-discount)

4:
Sumx (x denotes row by row calculation)

wt. avg. discount =


SUMX(Orders,Orders[MRP]*Orders[Discount])/SUM(Orders[MRP])
This is the expressing for weighted avg discount

5.
wt.av. profit% =
SUMX(Orders,Orders[Sales]*Orders[profit%]/sum(Orders[Sales]))
Where profit% is sum(profit) /sum(sales)

7:

date of month =
date(Orders[Order Date].[Date])
Same way we can find the month year as well

quarter of year =
QUARTER(Orders[Order Date].[Date])

8: This is used to get the days after which order was delivered (days to ship )

days to ship
= DATEDIFF(Orders[Order Date].[Date],Orders[Ship Date].[Date],day)

WT AVG DAYS ON Ship =


SUMX(Orders,Orders[Sales]*Orders[days to ship])/SUM(Orders[Sales])

note:::Concatenate is used to merge two words

9: This is used to create new table


customer_name = SUMMARIZE(Orders,Orders[Customer Name])
customer_name = SUMMARIZE(Orders,Orders[Customer Name],"total
sales",SUM(Orders[Sales]))
This is to get total name without duplicacy with summarizes sales value
customer_name =
SUMMARIZE(Orders,Orders[Customer Name],"total sales",SUM(Orders[Sales]),
"first purchase",MIN(Orders[Order Date].[Date]))

Bellow expression is use to get the days duration customer


was with the partner,total sales ,last purchase ,first
purchase
customer_name =
SUMMARIZE(Orders,Orders[Customer Name],"total sales",SUM(Orders[Sales]),
"first purchase",MIN(Orders[Order Date].[Date]),"last purchase",MAX(Orders[Order
Date].[Date]),"customers life",DATEDIFF(MIN(Orders[Order Date].
[Date]),MAX(Orders[Order Date].[Date]),DAY))

customer_name =
SUMMARIZE(Orders,Orders[Customer Name],"sales total",SUM(Orders[Sales]),
"first order", MIN(Orders[Order Date]),
"last order",MAX(Orders[Order Date]),
"customers life",DATEDIFF(MIN(Orders[Order
Date].[Date]),MAX(Orders[Order Date].[Date]),DAY),
"AVG.Customer sales/day",SUM(Orders[Sales])/DATEDIFF(MIN(Orders[Order Date].
[Date]),MAX(Orders[Order Date].[Date]),DAY)
)

FILTERS
10…This expression is used to get the top 20 form the summarized sales or new table
produc_wise_sales = TOPN(20,
SUMMARIZE(Orders,Orders[Product Name],"total
sales",SUM(Orders[Sales])),[total sales],DESC)

or

produc_wise_sales = TOPN(20,
SUMMARIZE(Orders,Orders[Product Name],
"Total quantity",SUM(Orders[Quantity]),
"total sales",SUM(Orders[Sales]),
"avg sales/quantity",SUM(Orders[Sales])/SUM(Orders[Quantity])
),[total sales],DESC)

11.
produc_wise_sales by year =
ADDCOLUMNS(
SUMMARIZE(Orders,Orders[Product Name],Orders[year or order],
"Total quantity",SUM(Orders[Quantity]),
"total sales",SUM(Orders[Sales]),
"avg sales/quantity",SUM(Orders[Sales])/SUM(Orders[Quantity])
),
"rank of sales",
RANKX(SUMMARIZE(Orders,Orders[Product Name],Orders[year or order],
"Total quantity",SUM(Orders[Quantity]),
"total sales",SUM(Orders[Sales]),
"avg sales/quantity",SUM(Orders[Sales])/SUM(Orders[Quantity])
),[total sales],,DESC
))

This expression is used to ger the ranking of the table, below table does the
same but to reduce the line of code we haveused VAR to create the table and
use it for the other expression
produc_wise_sales by year =
var sales_table=
SUMMARIZE(

Orders,Orders[Product Name],Orders[year or order],


"total sales",SUM(Orders[Sales]),
"total quantity", SUM(Orders[Quantity]),
"avg. sales/quantity",SUM(Orders[Sales])/SUM(Orders[Quantity]))
return

ADDCOLUMNS(sales_table,
"rank of the table",
RANKX(sales_table,[total sales],,DESC

Return is used to say that VAR operation is over and give the return of the table
12. This is used to find sales with rank
Top 20 sales are produced with this expression.
In this we have used filter , instead of filter
one can use TOP N
sales with rank =
FILTER(
SUMMARIZE(
Orders,Orders[Product Name],Orders[year or order],
"total sales",SUM(Orders[Sales]),
"total quantity",SUM(Orders[Quantity]),
"avg.
sales/order",SUM(Orders[Sales])/SUM(Orders[Quantity])),

RANKX(
SUMMARIZE(
Orders,Orders[Product Name],Orders[year or order],
"total sales",SUM(Orders[Sales]),
"total quantity",SUM(Orders[Quantity]),
"avg.
sales/order",SUM(Orders[Sales])/SUM(Orders[Quantity])),

[total sales],,DESC

)<=20
)
12.
This is same as above changes are lines of codes are shorten
and sales with ranks till 20 are presented with one column
added

sales with rank 20 =


var sales_table=SUMMARIZE(
Orders,Orders[Product Name],Orders[year or order],
"total sales",SUM(Orders[Sales]),
"total quantity",SUM(Orders[Quantity]),
"avg.
sales/order",SUM(Orders[Sales])/SUM(Orders[Quantity]))
return
ADDCOLUMNS(
FILTER(sales_table,
RANKX(
sales_table,
[total sales],,DESC
)<=20
),
"rank of sales",
RANKX(sales_table,[total sales],,DESC
))

This will be the desired out put

12.

If you want to get top 20 sales ranking of each year , so there will be 80 rows
Comparative Analysis Dashboard
First we have created new table and created new column

DATE_DIMENTION = CALENDARAUTO()

This will extract date from other table

year = DATE_DIMENTION[Date].[Year]

This will extract year from the data source

This is used to get current year sales (dax)


CY SALES =
VAR CY= MAX(DATE_DIMENTION[Date].[Year])
RETURN
CALCULATE(SUM(Sales[Sale Amount]),DATE_DIMENTION[year]=CY)

For previous year sales


py_sales = CALCULATE([CY
SALES],SAMEPERIODLASTYEAR(DATE_DIMENTION[Date]))

Yoy growth
yoy sales growth = DIVIDE([CY SALES]-[py_sales],[py_sales],BLANK())

Budget variances are the differences between the actual and planned amounts of
income and expenses for a given period.
BUDGETED VARIANCE%
BUDGETED VARIANCE% = DIVIDE([CY SALES]-Budget[budgeted
sales],Budget[budgeted sales],BLANK())
Revision and practice(batch 3084)

Class 4
wtd_avg_discount1 =divide
SUMX(Orders,Orders[Discount]*Orders[mrp]),SUM(Orders[mrp]))

This is used to calculate wtd average discount4

In the below one it will show profit gained per quantity


%profit per quantity =
DIVIDE(SUMX(Orders,[profit
%]*Orders[Quantity]),SUM(Orders[Quantity]))

If you want to extract data for 1 year form the main source data and create
another table
2014 table =
FILTER(Orders,YEAR(Orders[Order Date].[Date])=2014)

Datediff is used to find the average days taken to deliver the product
AVG_DELIVERY_DATE = DATEDIFF('2014 table'[Order Date].[Date],'2014 table'[Ship Date].
[Date],DAY)

Same period last year DAX


PYTS SALES = CALCULATE(SUM(Orders[Sales]),
SAMEPERIODLASTYEAR(Orders[Order Date].[Date]))
This is the dax to compare same period last year
Returns a table that contains a column of dates shifted one year back in time from the
dates in the specified dates column, in the current context.
5TH class
Interview 1
The sales table have sales for 2023 extract till today sales
1 first we will create new table with dates without duplicate valuesby
using below dax
date_table =
CALENDAR(MIN(Table1[Order Date]),MAX(Table1[Order Date]))

2 from the below expression we can get YTD sales ,so only sales from
the starting to till today
ytd sales =
CALCULATE(TOTALYTD(SUM(Table1[sales]),date_table[Date]),date_table[Date]
<=TODAY())

3.create montly trend chart for sale the sequence of thr months in the
chart should be as per united states financial year?

This is used to extract months form the dates


month =
FORMAT(date_table[Date].[Date],"mmmm")

Then after that create line chart of month vs sales


after that we will find month number

month_number =
MONTH(date_table[Date].[Date])

Then we have to get range for financial year of US which start from
sep and end october
month range=
IF(date_table[month_number]>9,date_table[month_number]-
9,date_table[month_number]+3
This will be th desired out put

4.Hwo to create dynamic title ?


dynamic_title =
"sales for year" & SELECTEDVALUE(date_table[year])

For any column can create


After creating DAX we have to go to general and then title

Create a bar chart using subcategory and sum of sales. Add green colour to the
subcategory bars if sum of sales are greater than 150000 ands red colour if sum of sales
are less than 150000?
colur indicator = IF(SUM(Table1[Sales])>150000,"red","green")

Then go to bard and select functional formatting

Theoretical
What is powerBI?
It is a visualisation or business analytical tool developed by Microsoft which
converts unrelarted data into valuable and interactive insights.

Difference between power bi and tableau?

Components and features of power BI?


Components of Power BI
1. Power Query

Power Query helps to discover, connect, combine, and refine data sources to

meet your analysis need.

2. Power Pivot

Power pivot is a data modeling technique to create models and establish

relationship calculations.

3. Power View

Power view helps to create interactive charts, graphs, maps, and other visuals in

Excel, SharePoint, SQL Server, and Power BI that bring data to life.

4. Power Map

Power map is a 3-D data visualization tool.

5. Power BI Desktop

Power BI desktop helps to get everything easily under the same solution to

develop BI and data analysis experience.

6. Power Q&A
Power Q&A is used to explore data in the fastest way to get an answer using

natural language. For example, an answer to a question like what was the total

sales last year?

What are the versions of power BI?


Free per user - licence
● Users with free licenses can use the Power BI service to connect to data and
create reports and dashboards for their own use.
● They can't use the Power BI sharing or collaborating features with others, or
publish content to other people's workspaces.
● However, Pro and PPU users can share content and collaborate with free users
if the content is saved in workspaces hosted in Premium capacity.

Pro licence

● Power BI Pro is an individual per-user license that lets users create content and
also read, and interact with content that others have published to the Power BI
service.
● Users with this license type can share content and collaborate with other Power
BI Pro users.

Premium per used (PPU)

● Can do all

What is power pivot.?


This is the addon to the microsoft exel to extend the analytical capabilities and
service of microsoft

What is power quesrty ?


Power query is a business intelligence tool , it allows to import data form various
data sources and and it will enable it to clean , transform and reshape the data
as per requirement.

What is DAX ?
DAX is a data analytics expression ,its a collection of functions,operators,used in
formula to calculate and return value to create measures and new tables, by
using these we can dig more insightful data.

Some advantages of power BI?


● It is user friendly so even a non tech background can easly use it
● It helps to buid intractable data visualisation
● It allows use to transform data into visualisation and transfer to any one
Drawbacks
It does not allow data beyond 1gb
You can only share data and dashboard with the same versions.

What are the different connectivity modesavailable in power BI?


SQL server import
An SQL Server Import is the default and most common connectivity type used in Power
BI. It allows you to use the full capabilities of the Power BI Desktop.

Direct Query

The Direct Query connection type is only available when you connect to specific data
sources. In this connectivity type, Power BI will only store the metadata of the
underlying data and not the actual data.

Live Connection

With this connectivity type, it does not store data in the Power BI model. All interaction
with a report using a Live Connection will directly query the existing Analysis Services
model. There are only 3 data sources that support the live connection method - SQL
Server Analysis Services (Tabular models and Multidimensional Cubes), Azure Analysis
Services (Tabular Models), and Power BI Datasets hosted in the Power BI Service.

Name the data sources a file can POWER BI connect ?

You might also like