前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Power BI同期对比这么看

Power BI同期对比这么看

作者头像
wujunmin
发布2022-05-19 08:49:00
1.4K0
发布2022-05-19 08:49:00
举报
文章被收录于专栏:wujunmin

同期对比常规状态下可以使用簇状条形图/柱形图,以下是Power BI内置图表的效果。

这个图表的缺陷是,无法反映增长率。以下是使用DAX自定义图表,优化后的效果:

气泡的面积大小代表增长率的大小,颜色区分增长还是下降。图表的度量值如下,把度量值中的今年、同期、增长率替换为你模型中的值,并把度量值放入HTML Content视觉对象即可正常出图,图表可与外部切片器正常联动。度量值的结构见注释。

代码语言:javascript
复制
同期对比组合图 = 
VAR Height_Rect = 12 //每个条形高度,12像素
VAR Height_Item = 2 * Height_Rect + 5 //两年对比,每个维度数据间隔5个像素
VAR Width_ItemLabel = 60 //类别标签宽度
VAR Width_Rect = 100 //条形最大长度
VAR FontSize = 6 //字号
VAR Circle_R = Height_Rect //圆圈的最大半径
VAR Space_Btw_Rect_Circle = Width_Rect * 0.3 + Circle_R
VAR ItemCount =
    DISTINCTCOUNT ( '店铺信息'[店铺名称] )
VAR MaxValue_ThisYear =
    MAXX ( VALUES ( '店铺信息'[店铺名称] ), [业绩_今年] )
VAR MaxValue_LastYear =
    MAXX ( VALUES ( '店铺信息'[店铺名称] ), [业绩_同期] )
VAR MaxValue =
    MAX ( MaxValue_ThisYear, MaxValue_LastYear )
VAR MaxGrowth =
    MAXX ( VALUES ( '店铺信息'[店铺名称] ), ABS ( [增长率] ) )
VAR BarTable =
    ADDCOLUMNS (
        SUMMARIZE (
'店铺信息',
'店铺信息'[店铺名称],
"Index", RANKX ( ALLSELECTED ( '店铺信息' ), [业绩_今年] )
        ),
"Store",
//画类别标签                           公众号:wujunmin
"<text x='" & Width_ItemLabel - 1 & "' y='" & ( [Index] - 1 ) * Height_Item + Height_Rect & "'  text-anchor='end' dominant-baseline='middle' font-weight='bold' font-size='" & FontSize & "' >" & [店铺名称] & "</text>",
"Rect_Background",
//画背景框
"<rect x='" & Width_ItemLabel & "' y='" & ( [Index] - 1 ) * Height_Item + + Height_Rect / 2 & "' width='" & Width_Rect + Space_Btw_Rect_Circle & "' height='" & Height_Rect & "' fill='none' stroke='LightGrey' stroke-width='0.5'/>",
"Rect",
//画本期条形
"<rect x='" & Width_ItemLabel & "' y='" & ( [Index] - 1 ) * Height_Item & "' width='" & Width_Rect * [业绩_今年] / MaxValue & "' height='" & Height_Rect & "' fill='DarkCyan'/>",
"Rect_L",
//画同期条形
"<rect x='" & Width_ItemLabel & "' y='" & ( [Index] - 1 ) * Height_Item + Height_Rect & "' width='" & Width_Rect * [业绩_同期] / MaxValue & "' height='" & Height_Rect & "' fill='LightGrey'/>",
"Text",
//画本期数据标签
"<text x='" & Width_ItemLabel & "' y='" & ( [Index] - 1 ) * Height_Item + + Height_Rect / 2 & "' text-anchor='start' dominant-baseline='middle' font-size='" & FontSize & "' >"
                & FORMAT ( [业绩_今年] , "#,##" ) & "</text>",
"Text_L",
//画同期数据标签
"<text x='" & Width_ItemLabel & "' y='" & ( [Index] - 1 ) * Height_Item + + Height_Rect + Height_Rect / 2 & "' text-anchor='start' dominant-baseline='middle' font-size='" & FontSize & "' >"
                & FORMAT ( [业绩_同期] , "#,##" ) & "</text>",
"Circle",
//画气泡
"<circle cx='" & Width_ItemLabel + Width_Rect + Space_Btw_Rect_Circle & "' cy='" & ( [Index] - 1 ) * Height_Item + Height_Rect & "' r='"
                & Circle_R
                    * SQRT ( ABS ( [增长率] ) / MaxGrowth ) & "' fill='"
                & IF ( [增长率] >= 0, "LightSeaGreen", "Tomato" ) & "' fill-opacity='1'/>",
"Percent",
//画增长率数据标签                           公众号:wujunmin
"<text x='" & Width_ItemLabel + Width_Rect + Space_Btw_Rect_Circle & "' y='" & ( [Index] - 1 ) * Height_Item + Height_Rect & "'  text-anchor='middle' dominant-baseline='middle' font-size='" & FontSize & "' >"
                & FORMAT ( [增长率], "0%" ) & "</text>"
    )
VAR Bar =
    CONCATENATEX (
        BarTable,
        [Store] & [Rect_Background] & [Rect] & [Rect_L] & [Text] & [Text_L] & [Circle] & [Percent]
    )
VAR SVG = "<svg xmlns='http://www.w3.org/2000/svg' viewbox='0 0 " & Width_ItemLabel + Width_Rect + Space_Btw_Rect_Circle + Circle_R & " " & Height_Item * ItemCount & "'>" & Bar & "</svg>"
RETURN
    SVG
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-05-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 wujunmin 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云 BI
腾讯云 BI(Business Intelligence,BI)提供从数据源接入、数据建模到数据可视化分析全流程的BI能力,帮助经营者快速获取决策数据依据。系统采用敏捷自助式设计,使用者仅需通过简单拖拽即可完成原本复杂的报表开发过程,并支持报表的分享、推送等企业协作场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档