ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 8782|回复: 27

[求助] 这张透视表的余额公式怎么写

[复制链接]

TA的精华主题

TA的得分主题

发表于 2010-10-17 12:55 | 显示全部楼层 |阅读模式
每个月都要做一张会计科目余额表,各个会计科目发生时,分借方金额和贷方金额。
编码1001~1603,有8项,属于资产类,余额=借方-贷方,现在表中的计算数字是正确的。
编码2171~3131,有5项,属负债、权益类,余额=贷方-借方,而现在表中的数字是根据上面的公式:余额=借方-贷方来的,所以现在黄色标注的余额是错的,要再乘-1才对。

请教:在数据透视表插入计算字段时,用什么方法,根据编码的规律,在计算余额时能正确选择公式?

[ 本帖最后由 平帆 于 2010-10-17 13:55 编辑 ]
11.jpg

会计帐10.17.rar

27.8 KB, 下载次数: 90

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2010-10-17 15:44 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
  1. select *,iif(贷方金额 is null,0,贷方金额)-iif(借方金额 is null,0,借方金额) as 余额,贷方金额-0 as 贷方,借方金额-0 as 借方 from( select * from [现金$a:i]  union all   select * from [银行存款$a:i]  union all   select * from [应收帐款$a:i]  union all   select * from [其他应收款$a:i]  union all   select * from [长期股权投资$a:i]  union all   select * from [待摊费用$a:i]  union all   select * from [固定资产$a:i]  union all   select * from [在建工程$a:i]  union all   select * from [其他应交款$a:i]  union all   select * from [应交税金$a:i]  union all   select * from [其他应付款$a:i]  union all   select * from [实收资本$a:i]  union all   select * from [本年利润$a:i]  union all   select * from [生产成本$a:i]  union all   select * from [制造费用$a:i]  union all   select * from [主营业务收入$a:i]  union all   select * from [主营业务成本$a:i]  union all   select * from [管理费用$a:i]  union all   select * from [财务费用$a:i]  union all   select * from [营业外支出$a:i]) where 编码 like '[23]%'
  2. union all
  3. select *,iif(借方金额 is null,0,借方金额)-iif(贷方金额 is null,0,贷方金额) as 余额,贷方金额-0 as 贷方,借方金额-0 as 借方 from( select * from [现金$a:i]  union all   select * from [银行存款$a:i]  union all   select * from [应收帐款$a:i]  union all   select * from [其他应收款$a:i]  union all   select * from [长期股权投资$a:i]  union all   select * from [待摊费用$a:i]  union all   select * from [固定资产$a:i]  union all   select * from [在建工程$a:i]  union all   select * from [其他应交款$a:i]  union all   select * from [应交税金$a:i]  union all   select * from [其他应付款$a:i]  union all   select * from [实收资本$a:i]  union all   select * from [本年利润$a:i]  union all   select * from [生产成本$a:i]  union all   select * from [制造费用$a:i]  union all   select * from [主营业务收入$a:i]  union all   select * from [主营业务成本$a:i]  union all   select * from [管理费用$a:i]  union all   select * from [财务费用$a:i]  union all   select * from [营业外支出$a:i]) where 编码 not like '[23]%'
复制代码

TA的精华主题

TA的得分主题

发表于 2010-10-17 16:10 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
不会会计的记帐方法,帮不了你

TA的精华主题

TA的得分主题

发表于 2010-10-17 16:39 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
只在前面中个判断,不知道对不对。
select *,
iif(名称="应交税金" or 名称="其他应付款" or 名称="其他应交款" or 名称="实收资本" or 名称="本年利润", 0-贷方金额, 贷方金额-0) as "贷方" ,
iif(名称="应交税金" or 名称="其他应付款" or 名称="其他应交款" or 名称="实收资本" or 名称="本年利润", 0-借方金额, 借方金额-0) as "借方"
from
(
select * from [现金$a:i]  
union all   
select * from [银行存款$a:i]  
union all   
select * from [应收帐款$a:i]  
union all   
select * from [其他应收款$a:i]  
union all   
select * from [长期股权投资$a:i]  
union all   
select * from [待摊费用$a:i]  
union all   
select * from [固定资产$a:i]  
union all   
select * from [在建工程$a:i]  
union all   
select * from [其他应交款$a:i]  
union all   
select * from [应交税金$a:i]  
union all   
select * from [其他应付款$a:i]  
union all   
select * from [实收资本$a:i]  
union all   
select * from [本年利润$a:i]  
union all   
select * from [生产成本$a:i]  
union all   
select * from [制造费用$a:i]  
union all   
select * from [主营业务收入$a:i]  
union all   
select * from [主营业务成本$a:i]  
union all   
select * from [管理费用$a:i]  
union all   
select * from [财务费用$a:i]  
union all   
select * from [营业外支出$a:i])
QQ截图未命名.png

会计帐10.17.rar

44.38 KB, 下载次数: 54

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-10-17 18:57 | 显示全部楼层

回复 4楼 suwenkai 的帖子

虽然余额和我的要求对上了,但同一行数据都改了,如原先记账的是600,现在成了-600,正数变成了负数,所以还是没有达到我的要求。

[ 本帖最后由 平帆 于 2010-10-18 13:21 编辑 ]

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-10-17 19:07 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

回复 2楼 mn860429 的帖子

结果和我的要求一致了,你写的语句中
select * from [营业外支出$a:i]) where 编码 like '[23]%'  union all
这里的'[23]%'是什么含义?现在一共有20张工作表,如果再增加工作表,语句又该怎么写呢?

TA的精华主题

TA的得分主题

发表于 2010-10-17 19:39 | 显示全部楼层
就是以2或者3开头的编码,百分号是通配符和*的作用是一样的

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-10-17 20:08 | 显示全部楼层
哦,是这样,谢谢解答。还有一个问题,现在是20个会计科目20张表格,SQL字符数已有1761。如果再增加会计科目、增加工作表,SQL有字数限制,超过了怎么办?
02.jpg

TA的精华主题

TA的得分主题

发表于 2010-10-17 20:35 | 显示全部楼层
修改了一下。

select *,
val(iif(借方金额 is null,0,借方金额)) as "借方",
val(iif(贷方金额 is null,0,贷方金额)) as "贷方",
iif(名称="应交税金" or 名称="其他应付款" or 名称="其他应交款" or 名称="实收资本" or 名称="本年利润",
val(iif(贷方金额 is null,0,贷方金额)) -
val(iif(借方金额 is null,0,借方金额)),
val(iif(借方金额 is null,0,借方金额)) -
val(iif(贷方金额 is null,0,贷方金额))
)as 余额
from
(
select * from [现金$a:i]  
union all   
select * from [银行存款$a:i]  
union all   
select * from [应收帐款$a:i]  
union all   
select * from [其他应收款$a:i]  
union all   
select * from [长期股权投资$a:i]  
union all   
select * from [待摊费用$a:i]  
union all   
select * from [固定资产$a:i]  
union all   
select * from [在建工程$a:i]  
union all   
select * from [其他应交款$a:i]  
union all   
select * from [应交税金$a:i]  
union all   
select * from [其他应付款$a:i]  
union all   
select * from [实收资本$a:i]  
union all   
select * from [本年利润$a:i]  
union all   
select * from [生产成本$a:i]  
union all   
select * from [制造费用$a:i]  
union all   
select * from [主营业务收入$a:i]  
union all   
select * from [主营业务成本$a:i]  
union all   
select * from [管理费用$a:i]  
union all   
select * from [财务费用$a:i]  
union all   
select * from [营业外支出$a:i])

TA的精华主题

TA的得分主题

 楼主| 发表于 2010-10-17 21:00 | 显示全部楼层

回复 9楼 suwenkai 的帖子

现在对上了,符合我的要求,谢谢你!你的语句还有一个优点,就是字符数比较少,
是1092个。
还有一个不是问题的问题,为什么财务费用的余额是0,显示的却是科学计数法,和其他的不一样。

[ 本帖最后由 平帆 于 2010-10-18 13:19 编辑 ]
04.jpg
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-4 21:24 , Processed in 0.046985 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表