前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Power BI 豪华动态盈亏平衡分析

Power BI 豪华动态盈亏平衡分析

作者头像
wujunmin
发布2025-03-24 19:26:03
发布2025-03-24 19:26:03
6200
代码可运行
举报
文章被收录于专栏:wujunminwujunmin
运行总次数:0
代码可运行

盈亏平衡分析是一种用于确定企业或项目在何时达到收入与成本相等的分析方法。它帮助管理者了解在特定条件下,需要多少销售量或收入才能覆盖所有成本,从而实现盈亏平衡。

盈亏平衡涉及几个关键的概念。

固定成本指不随销量/生产量变动的成本,比如门店租金、员工底薪。

变动成本是随销量/生产量变动的成本,比如商品/原料的采购成本,每多一件就多点进货成本。再比如员工提成,每多销售一件会给员工多发一些工资。同样的成本在不同的企业可能归属不同,比如水电费在零售门店属于固定成本,但在生产企业可能属于变动成本。

总成本是固定成本和变动成本之和。

总收入是销售产品产生的收入。

盈亏平衡点是总收入等于总成本时的销售量或收入。

在Power BI可以不使用外部数据源,通过控制固定成本、单位变动成本、单位售价三个参数进行动态盈亏平衡分析。

上图输入三个参数后,点击生成分析图表按钮,即可生成图表展示不同销量的收入、成本、利润状况,并突出显示盈亏平衡点。最下方有文字说明列出所有关键信息。视频操作演示:

整个模型使用一个HTML度量值生成,度量值如下,放入HTML Content视觉对象即可正常显示:

代码语言:javascript
代码运行次数:0
运行
复制
HTML图= 
"<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>盈亏平衡分析图表</title>
    <script src='https://code.highcharts.com/highcharts.js'></script>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            margin: 0;
            padding: 0;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .container {
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            padding: 30px;
            width: 90%;
            max-width: 1000px;
            margin: 20px auto;
        }
        /* 其他CSS样式保持不变 */
        h1 {
            text-align: center;
            color: #3a4a6d;
            margin-bottom: 30px;
            font-size: 2.2rem;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
        }
        .input-section {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            margin-bottom: 30px;
            justify-content: center;
        }
        .input-group {
            flex: 1;
            min-width: 200px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            color: #3a4a6d;
            font-weight: bold;
        }
        input {
            width: 100%;
            padding: 12px;
            border: 2px solid #c3cfe2;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        input:focus {
            border-color: #3a4a6d;
            outline: none;
        }
        button {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: bold;
            transition: transform 0.2s, box-shadow 0.2s;
            margin: 0 auto;
            display: block;
        }
        button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .chart-container {
            position: relative;
            margin: 20px auto;
            height: 400px;
        }
        .results {
            background-color: #f0f4f8;
            padding: 20px;
            border-radius: 10px;
            margin-top: 30px;
        }
        .result-item {
            margin-bottom: 10px;
            font-size: 18px;
            color: #3a4a6d;
        }
        .highlight {
            font-weight: bold;
            color: #764ba2;
        }
        .legend {
            display: flex;
            justify-content: center;
            margin-top: 20px;
            flex-wrap: wrap;
            gap: 20px;
        }
        .legend-item {
            display: flex;
            align-items: center;
            margin-right: 15px;
        }
        .legend-color {
            width: 20px;
            height: 20px;
            margin-right: 8px;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class='container'>
        <h1>盈亏平衡分析模型</h1>
        
        <div class='input-section'>
            <div class='input-group'>
                <label for='fixedCost'>固定成本 (元)</label>
                <input type='number' id='fixedCost' value='100000' min='0'>
            </div>
            <div class='input-group'>
                <label for='variableCost'>单位变动成本 (元)</label>
                <input type='number' id='variableCost' value='50' min='0'>
            </div>
            <div class='input-group'>
                <label for='sellingPrice'>单位售价 (元)</label>
                <input type='number' id='sellingPrice' value='100' min='0'>
            </div>
        </div>
        
        <button onclick='calculateAndDraw()'>生成分析图表</button>
        
        <div class='chart-container' id='breakEvenChart'>
            <!-- Highcharts将在这里渲染 -->
        </div>
        
        <div class='legend'>
            <div class='legend-item'>
                <div class='legend-color' style='background-color: #FF6384;'></div>
                <span>总成本</span>
            </div>
            <div class='legend-item'>
                <div class='legend-color' style='background-color: #36A2EB;'></div>
                <span>总收入</span>
            </div>
            <div class='legend-item'>
                <div class='legend-color' style='background-color: #4BC0C0;'></div>
                <span>固定成本</span>
            </div>
            <div class='legend-item'>
                <div class='legend-color' style='background-color: #9966FF;'></div>
                <span>利润/亏损</span>
            </div>
        </div>
        
        <div class='results' id='results'>
            <div class='result-item'>请输入参数并点击'生成分析图表'按钮查看结果。</div>
        </div>
    </div>
    <script>
        let chart = null;
        
        function calculateAndDraw() {
            const fixedCost = parseFloat(document.getElementById('fixedCost').value);
            const variableCost = parseFloat(document.getElementById('variableCost').value);
            const sellingPrice = parseFloat(document.getElementById('sellingPrice').value);
            
            // 验证输入
            if (isNaN(fixedCost) || isNaN(variableCost) || isNaN(sellingPrice)) {
                alert('请输入有效的数字');
                return;
            }
            
            if (sellingPrice <= variableCost) {
                alert('单位售价必须大于单位变动成本才能达到盈亏平衡');
                return;
            }
            
            // 计算盈亏平衡点
            const breakEvenPoint = fixedCost / (sellingPrice - variableCost);
            const breakEvenRevenue = breakEvenPoint * sellingPrice;
            
            // 为图表准备数据
            const maxUnits = Math.ceil(breakEvenPoint * 2);
            const step = Math.ceil(maxUnits / 20);
            
            const units = [];
            const totalRevenue = [];
            const totalCost = [];
            const fixedCostLine = [];
            const profitLoss = [];
            
            for (let i = 0; i <= maxUnits; i += step) {
                units.push(i);
                const revenue = i * sellingPrice;
                const cost = fixedCost + (i * variableCost);
                
                totalRevenue.push([i, revenue]);
                totalCost.push([i, cost]);
                fixedCostLine.push([i, fixedCost]);
                profitLoss.push([i, revenue - cost]);
            }
            
            // 使用Highcharts绘制图表
            chart = Highcharts.chart('breakEvenChart', {
                title: {
                    text: '盈亏平衡图',
                    style: {
                        fontSize: '18px',
                        fontWeight: 'bold',
                        color: '#3a4a6d'
                    }
                },
                xAxis: {
                    title: {
                        text: '销售数量 (单位)',
                        style: {
                            fontWeight: 'bold'
                        }
                    },
                    labels: {
                        formatter: function() {
                            return this.value.toLocaleString();
                        }
                    },
                    plotLines: [{
                        value: breakEvenPoint,
                        color: 'rgba(255, 0, 0, 0.5)',
                        width: 2,
                        dashStyle: 'Dash',
                        label: {
                            text: '盈亏平衡点',
                            align: 'center',
                            style: {
                                color: 'red',
                                fontWeight: 'bold'
                            }
                        }
                    }]
                },
                yAxis: {
                    title: {
                        text: '金额 (元)',
                        style: {
                            fontWeight: 'bold'
                        }
                    },
                    labels: {
                        formatter: function() {
                            return this.value.toLocaleString() + '元';
                        }
                    }
                },
                tooltip: {
                    formatter: function() {
                        return '<b>' + this.series.name + '</b><br/>' +
                               '销售数量: ' + this.x.toLocaleString() + ' 单位<br/>' +
                               '金额: ' + this.y.toLocaleString() + ' 元';
                    }
                },
                legend: {
                    enabled: false // 使用自定义图例
                },
                series: [{
                    name: '总成本',
                    data: totalCost,
                    color: '#FF6384',
                    lineWidth: 3
                }, {
                    name: '总收入',
                    data: totalRevenue,
                    color: '#36A2EB',
                    lineWidth: 3
                }, {
                    name: '固定成本',
                    data: fixedCostLine,
                    color: '#4BC0C0',
                    lineWidth: 3,
                    dashStyle: 'Dash'
                }, {
                    name: '利润/亏损',
                    data: profitLoss,
                    color: '#9966FF',
                    lineWidth: 3
                }],
                credits: {
                    enabled: false // 移除Highcharts水印
                },
                responsive: {
                    rules: [{
                        condition: {
                            maxWidth: 500
                        },
                        chartOptions: {
                            legend: {
                                layout: 'horizontal',
                                align: 'center',
                                verticalAlign: 'bottom'
                            }
                        }
                    }]
                }
            });
            
            // 显示结果
            const resultsDiv = document.getElementById('results');
            resultsDiv.innerHTML = `
                <div class='result-item'>固定成本: <span class='highlight'>${fixedCost.toLocaleString()}元</span></div>
                <div class='result-item'>单位变动成本: <span class='highlight'>${variableCost.toLocaleString()}元</span></div>
                <div class='result-item'>单位售价: <span class='highlight'>${sellingPrice.toLocaleString()}元</span></div>
                <div class='result-item'>单位贡献毛利: <span class='highlight'>${(sellingPrice - variableCost).toLocaleString()}元</span></div>
                <div class='result-item'>盈亏平衡点 (销售数量): <span class='highlight'>${Math.ceil(breakEvenPoint).toLocaleString()}单位</span></div>
                <div class='result-item'>盈亏平衡点 (销售收入): <span class='highlight'>${Math.ceil(breakEvenRevenue).toLocaleString()}元</span></div>
                <div class='result-item'>安全边际率: <span class='highlight'>${((maxUnits - breakEvenPoint) / maxUnits * 100).toFixed(2)}%</span></div>
            `;
        }
        
        // 页面加载时自动生成图表
        window.onload = calculateAndDraw;
    </script>
</body>
</html>"

如有样式调整的需求,可以把代码甩给AI进行修改,以下换了一种风格:

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-03-23,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档