AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1674273
Accepted
Random Person
Random Person
Asked: 2021-09-05 08:24:01 +0800 CST2021-09-05 08:24:01 +0800 CST 2021-09-05 08:24:01 +0800 CST

如何在 Excel 中找到我的情况的平均值?

  • 772

假设这是我 2020 年 7 月的银行对账单:

SL。不。 交易日期 退出 订金 余额
1 01-07-2020 100 100
2 02-07-2020 5 95
3 03-07-2020 500 595
4 06-07-2020 50 545
5 06-07-2020 8000 8545
6 06-07-2020 3000 5545
7 31-07-2020 5 5540
8 31-07-2020 10000 15540

现在我想知道我的每月平均余额。

要找到它,我必须将所有日终余额相加,然后除以天数。但是,银行对账单没有日终余额,只列出交易及其各自的日期。声明中没有提到没有交易发生的日子。

现在,假设我有一张银行对账单的 Excel 表格。我怎样才能找到每月平均余额?我读了一些关于 AVERAGEIF 的东西,但我不确定它是否对我有帮助。


这是我找到平均值的方法(但这是一个漫长的过程):

  1. 我查看当月的银行对账单,然后找出每天的最终交易,这将帮助我找到日终余额。

  2. 现在我将打开一个新的 Excel 表,并像这样提及日终余额:

    日期 日终余额
    01-07-2020 100
    02-07-2020 95
    03-07-2020 595
    04-07-2020 595
    05-07-2020 595
    06-07-2020 5545
    07-07-2020 5545
    08-07-2020 5545
    09-07-2020 5545
    10-07-2020 5545
    11-07-2020 5545
    12-07-2020 5545
    13-07-2020 5545
    14-07-2020 5545
    15-07-2020 5545
    16-07-2020 5545
    17-07-2020 5545
    18-07-2020 5545
    19-07-2020 5545
    20-07-2020 5545
    21-07-2020 5545
    22-07-2020 5545
    23-07-2020 5545
    2020 年 7 月 24 日 5545
    25-07-2020 5545
    2020 年 7 月 26 日 5545
    27-07-2020 5545
    28-07-2020 5545
    2020 年 7 月 29 日 5545
    30-07-2020 5545
    31-07-2020 15540
  3. 最后,我将使用 AVERAGE 函数。因此,7 月份的平均值为 5036.935484

这是一个相当乏味的过程。有没有办法让这更容易?

microsoft-excel worksheet-function
  • 2 2 个回答
  • 69 Views

2 个回答

  • Voted
  1. CrazyEyesDave
    2021-09-05T11:34:14+08:002021-09-05T11:34:14+08:00

    假设您的表格从 A1 开始并以 E9 结束,但可能会更长很多:

    • 确保日期列 B 中的单元格格式正确为日期。
    • 在单元格 H2:H13 中写下每个月的第一个日期(2020 年 1 月 1 日、2020 年 1 月 2 日... 2020 年 1 月 12 日)
    • 格式化单元格 H2:H13 以改为显示月份(自定义 -> mmmm)。现在 H2:H13 单元格应该显示月份名称。
    • 在单元格 I3 中,编写以下公式: =IFERROR(AVERAGEIFS($E$2:$E$3000,$B$2:$B$3000,">="&$H2,$B$2:$B$3000,"<="&EOMONTH ($H2,0)),"-")
    • 在下面的单元格中复制公式 I4:I13

    现在,我认为我在从 E2 添加到 E3000 和从 B2 添加到 B3000 的公式中添加了足够的行,但是如果需要,如果您有更多行,您可以将这些“3000”更改为更多...

    此外,根据您的 Excel 版本和区域设置,您可能需要将公式 (,) 中的每个逗号替换为分号 (;)。我见过一些版本的 excel 需要分号而不是逗号。

    我在把它放在这里之前测试了这个公式,我确认它有效。对于缺失的月份或没有任何数据,公式将显示“-”。

    注意:如果您提取的年份更多,则需要将范围修改为只有 1 年,否则它将计算 9 月的平均值,例如多年。对于每一年,使用相同的公式在 H 列中再添加 12 个单元格,但具有相应年份的范围。

    在此处输入图像描述

    • 2
  2. Best Answer
    Ron Rosenfeld
    2021-09-06T02:12:16+08:002021-09-06T02:12:16+08:00

    你的方法是需要做的。

    一种更容易的方法是使用 VBA 宏或 Power Query 来做同样的事情。

    这是一个 Power Query 解决方案:

    使用 Power Query

    • 在数据表中选择一些单元格
    • Data => Get&Transform => from Table/Range
    • 当 PQ 编辑器打开时:Home => Advanced Editor
    • 记下第 2 行中的表名
    • 粘贴下面的 M 代码代替您看到的内容
    • 将第 2 行中的表名称更改回最初生成的名称。
    • 阅读评论并探索Applied Steps以了解算法

    M代码

    编辑1:更好的运行总算法编辑2
    :按年份区分
    我们所做的就是在生成年份的步骤中将年份添加到月份名称中

    let
    
    //Replace Table Name in the next line with actual table name in your workbook
        Source = Excel.CurrentWorkbook(){[Name="Table30"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{
            {"Sl. No.", Int64.Type}, 
            {"Tran Date", type date}, 
            {"Withdrawal", Currency.Type}, {"Deposit", Currency.Type}, {"Balance Amount", Currency.Type}
        }),
    
    //Replace nulls with 0 because cannot add nulls
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Withdrawal", "Deposit"}),
    
    //get starting balance. Should be last entry of previous month
    //but for here I will set it to 0
        startingBalance = 0,
    
    //Group by dates and get net of Withdrawal/Deposits for each date
        group = Table.Group(#"Replaced Value","Tran Date",{
            {"Net Change", each List.Sum([Deposit]) - List.Sum([Withdrawal]), Currency.Type}
        }),
    
    //create list of all dates in the statement
        monthDates = Table.FromList(
                let 
            mnthStart = Date.StartOfMonth(List.Min(#"Replaced Value"[Tran Date])),
            mnthEnd = Date.EndOfMonth(List.Max(#"Replaced Value"[Tran Date]))
                in List.Dates(mnthStart,Duration.Days(mnthEnd - mnthStart)+1, #duration(1,0,0,0)),
                    Splitter.SplitByNothing(),{"Month"}),
    
    //Merge with the dates from the grouped table
    // and sort to ensure proper date order
        allDates = Table.Join(group,"Tran Date", monthDates,"Month",JoinKind.RightOuter),
        #"Sorted Rows" = Table.Sort(allDates,{{"Month", Order.Ascending}}),
    
    //Remove partial date column 
        #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Tran Date"}),
    
    //Add running total column = end of day balance
    bl = List.Buffer(List.ReplaceValue(#"Removed Columns"[Net Change],null,0,Replacer.ReplaceValue)),
    RT = List.Generate(
            ()=>[rt=bl{0}, idx=0],
            each [idx] < List.Count(bl),
            each [rt = [rt] + bl{[idx]+1}, idx = [idx]+1],
            each [rt]
    ),
    rtTable = Table.FromColumns(
                {#"Removed Columns"[Month],RT},
                {"Date", "EOD Bal"}),
    
    //Convert date to month name
    //Add year to differentiate by year
        #"Added Custom1" = Table.AddColumn(rtTable, "MonthName", each Date.MonthName([Date]) & Date.ToText([Date]," yyyy")),
    
    //Group by monthName and aggregate by average
        #"Grouped Rows" = Table.Group(#"Added Custom1", {"MonthName"}, {{"Average Daily", each List.Average([EOD Bal]), type number}}),
    
    //set data types
        typed = Table.TransformColumnTypes(#"Grouped Rows",{{"MonthName", Text.Type},{"Average Daily", Currency.Type}})
    in
        typed
    

    原始数据
    在此处输入图像描述

    结果
    在此处输入图像描述

    • 1

相关问题

  • 如何对整列使用 Excel 的 LENGTH 函数?

  • Excel 数组(2 个变量)

  • 如何从 WSL 打开 office 文件

  • VBA根据文件名重命名工作表

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve