Power BI
什么是Power BI?相信360百科会给你满意的答复,我这里仅做简单的阐述。它的全称叫Power Business Intelligence,即商业智能增强版。由微软为Office组件提供的一套商业智能工具,包含四个插件:查询增强版(Power Query)、建模增强版(Power Pivot)、视图增强版(Power View)、地图增强版(Power Map),突破了Excel表格结构数据的短板。基本满足现代商业数据的业务分析需求,方便实用高效。
业务解读
一位做餐饮的老板想要掌握各家分店每天各时段的运营情况,以此及时调整、优化经营方案。对此,需要先搭建一个、多个多维度的信息交叉的数据表,并构建相关的观测指标。
从各分店的数据采集设备获得的原始数据信息分散在多个数据表中,这里需要先用MYSQL创建多维度的信息交叉的数据表,下面是三个原始数据表的字段说明。
结合餐饮业的实际经营情况,我们需要构建下面的KPI,来掌握所经营分店每天的运营状况,每个KPI的含义如下图所示。
数据准备
在MYSQL中用原始数据表创建多维度交叉信息所用的代码如下:
drop database ls;
create database cy;
use cy;
-- --------------创建三个表--------alter
create table Bill(
billdate date ,
billnumber varchar(20) not null default '-',
shopname varchar(20) not null default '-',
billdiscount float not null default 0,
paytime time not null,
tablenumber int not null default 0,
peoplecount int not null default 0
);
create table OrderDetail(
billnumber varchar(20) not null default '-',
detail varchar(20) not null default '-',
pay int not null default 0
);
create table ShopDetail(
ShopName varchar(20) not null default '-',
twotable int not null default 0,
threetable int not null default 0,
fourtable int not null default 0,
alltable int not null default 0
);
-- ----------------------------导入三个表-----------------------
load data local infile 'C:\\CDA data\\-bill.txt'
into table Bill
fields terminated by ',';
-- ignore 1 lines;
drop table Bill;
select * from Bill;
load data local infile 'C:\\CDA data\\-order.txt'
into table OrderDetail
fields terminated by '\,';
-- ignore 1 lines;
drop table OrderDetail;
select * from OrderDetail;
load data local infile 'C:\\CDA data\\-shop.txt'
into table ShopDetail
fields terminated by '\,';
-- ignore 1 lines;
drop table ShopDetail;
select * from ShopDetail;
select * from OrderDetail;
select * from Bill;
-- 数据加工
-- 创建单汇总金额表 drop table
drop table ordergroup;
create table ordergroup
(select billnumber, sum(pay) as pay
from orderdetail
group by billnumber);
select * from ordergroup;
drop table NewBill;
-- 创建新单号详细表
Create table NewBill(
select b.*,o.pay,b.billdiscount * o.pay as rebate
from bill as b left join ordergroup as o
on b.billnumber = o.billnumber);
select * from NewBill;
drop table NewShopDetail;
-- 创建新店面情况表
create table NewShopDetail(
select *, (twotable * 2 + threetable * 3 + fourtable * 6) as allseats
from shopdetail as s);
select * from NewShopDetail;
drop table neworderdetail;
-- 创建新点菜明细表
create table neworderdetail(
select b.shopname,o.*
from orderdetail as o left join bill as b
on o.billnumber = b.billnumber
);
select * from neworderdetail;
drop table ShopTotal;
-- 创建店汇总信息表
create table ShopTotal(
select b.shopname as 店名, count(b.billnumber) as 单数,
sum(b.peoplecount) as 人数,sum(b.rebate) as 折扣总金额,sum(b.pay) as 店汇总金额,
sum(b.pay)/count(b.billnumber) as 单均消费,
sum(b.pay)/sum(b.peoplecount) as 人均消费,
s.alltable as 总台数,
s.allseats as 总座位数,
count(b.billnumber)/s.alltable as 翻台率,
sum(b.peoplecount)/s.allseats as 上座率,
sum(b.rebate)/sum(b.pay) as 折扣率
from newbill as b ,newshopdetail as s
where b.shopname = s.shopname
group by b.shopname);
select * from shoptotal;
最后得到的多维度信息交叉数据表之一如下截图所示:
制作分析仪
得到最终的几个多维度交叉信息数据表后,便是将其所包含的信息以较好的方式展示给该餐饮老板。这里用到了Power BI 的Power Query、Power Pivot组件。利用Power Query查询数据表的关键信息以构建宽表,利用Power Pivot将查询到的数据进行规范调整。Power Query、Power Pivot的操作如下图所示。
最后通过Power Pivot的主页选项卡下的数据透视图、透视表等一系列细节处理得到该餐饮产业各分店的销售情况分析仪。该分析仪通过选取不同的店名,即可查看该分店当天各时段不同菜品的销售额变化情况及销量趋势、10个KPI则可展示不同分店的用餐资源使用情况及收益变化等信息。最后得到的分析仪如下图。