@云天明
第一就是条约规范
第二把这个连个表导入pq,然后做清洗。
第三说明:只是把你要的效果做出来了,由于对你的业务不是很清楚,pq写的有些冗余。参考吧。
条约
let
源 = Excel.Workbook(File.Contents("C:\Users\admin\Desktop\finance.xlsx"), null, true){[Item="付款条约",Kind="Sheet"]}[Data],
删除 = Table.SelectColumns(源,{"Column4", "Column5", "Column6", "Column7", "Column8", "Column9"}),
标题 = Table.PromoteHeaders(删除, [PromoteAllScalars=true]),
类型 = Table.TransformColumnTypes(标题,{{"厂家", type text}, {"首款方式", type text}, {"首款天数", Int64.Type}, {"首款比例", Int64.Type}, {"尾款方式", type text}, {"尾款天数", Int64.Type}})
in
类型
订单
let
源 = Excel.Workbook(File.Contents("C:\Users\admin\Desktop\finance.xlsx"), true, true){[Item="订单",Kind="Sheet"]}[Data],
类型 = Table.TransformColumnTypes(源,{{"订单号", Int64.Type}, {"订单日期", type date}, {"发货日期", type date}, {"到货日期", type date}, {"金额", type number}, {"厂家", type text}}),
自定义 = Table.AddColumn(类型, "自定义",
each
let
dt=Table.SelectRows(条约, (T)=> (T[厂家] = [厂家])) ,
sd=
if dt[首款方式]{0}="下订单" then [订单日期]+#duration(dt[首款天数]{0},0,0,0)
else if dt[首款方式]{0}="发货" then [发货日期]+#duration(dt[首款天数]{0},0,0,0)
else if dt[首款方式]{0}="到货" then [到货日期]+#duration(dt[首款天数]{0},0,0,0)
else [订单日期],
sp= dt[首款比例]{0}*[金额]/100,
ed=
if dt[尾款方式]{0}="下订单" then [订单日期]+#duration(dt[尾款天数]{0},0,0,0)
else if dt[尾款方式]{0}="发货" then [发货日期]+#duration(dt[尾款天数]{0},0,0,0)
else if dt[尾款方式]{0}="到货" then [到货日期]+#duration(dt[尾款天数]{0},0,0,0)
else [订单日期],
ep=[金额]-sp
in
[首款日期= sd ,
首款=if sd =null then null else sp,
尾款日期=ed,
尾款=if ed =null then null else ep]),
展开 = Table.ExpandRecordColumn(自定义, "自定义", {"首款日期", "首款", "尾款日期", "尾款"} ),
类型2 = Table.TransformColumnTypes(展开,{{"首款日期", type date}, {"尾款日期", type date}, {"首款", type number}, {"尾款", type number}})
in
类型2