English 中文(简体)
根据材料账单和购买价格史计算产品成本
原标题:Excel dynamically calculate cost of products based on bill of materials (BOM) and purchase price history

EDIT 1 → 2024-03-30:

  • Included parameters in the lambda functions so the table names and columns may be injected by the user
  • Updated lambda functions with such paramteres
  • Even though I found a solution, I tested the whole programming and it s really resource/memmory intensive.

必须设法优化/简化这一框架。



Objective:

根据《材料法案》计算一系列日期的产品成本,并购买每件材料的价格史(相对)


Process:

• 采购产品部件和数量达到购买水平,然后按每个月的购买价格乘以。

Source data

TableBOM 每个产品所需部件组合(Q = qty)

Componente 1 Q1 Componente 2 Q2 Resultado
Papel 1 1 Tarjeta personal 20 Tarjeta x20
Papel 2 2 Tarjetón 40 Tarjetón x40
Caja pe 4 Empaque pequeño
Cinta pe 5 Empaque pequeño
Separador pe 6 Empaque pequeño
Tarjeta x20 1 Empaque pequeño 1 Tarjeta empaque pe
Tarjetón x40 1 Empaque grande 1 Tarjetón empaque gr
Caja gr 7 Empaque grande
Cinta gr 8 Empaque grande
Nota 1 Empaque pequeño 1 Nota empaque pe
Tarjeta x20 1 Empaque grande 1 Tarjeta empaque gr
Tarjetón empaque gr 1 Nota empaque pe 2 Tarjetón + nota
Papel 3 3 Tarjetón
Divi gr 9 Empaque grande
Sobre 4 1 Nota sola 1 Nota

TablePurchaseComponent,每个材料的历史价格(相对)

Fecha Componente Precio unitario
1/01/2023 Caja gr 100
1/01/2023 Caja pe 110
1/01/2023 Cinta gr 120
1/01/2023 Cinta pe 130
1/01/2023 Divi gr 140
1/01/2023 Nota sola 150
1/01/2023 Papel 1 10
1/01/2023 Papel 2 20
1/01/2023 Papel 3 30
1/01/2023 Separador pe 190
1/01/2023 Sobre 4 200
1/01/2023 Tarjeta personal 2
1/01/2024 Caja gr 200
1/01/2024 Caja pe 220
1/01/2024 Cinta gr 240
1/01/2024 Cinta pe 260
1/01/2024 Divi gr 280
1/01/2024 Nota sola 300
1/01/2024 Papel 1 20
1/01/2024 Papel 2 40
1/01/2024 Papel 3 60
1/01/2024 Separador pe 380
1/01/2024 Sobre 4 400
1/01/2024 Tarjeta personal 4

表格:

“enterography


Lambda functions (as defined names):

fxProcessVal:

Parameters → lookup_val;component1_cols;component2_cols;result_col

法典:

=LET(
    comp_res; VSTACK(
        FILTER(component1_cols; result_col = lookup_val);
        FILTER(component2_cols; result_col = lookup_val)
    );
    comp_res_fil; FILTER(comp_res; CHOOSECOLS(comp_res; 2) <> "");
    lookup_col; IFNA(EXPAND(lookup_val; ROWS(comp_res_fil)); lookup_val);
    IFERROR(HSTACK(lookup_col; comp_res_fil); "")
)

<fxProcessCompRow>:

参数:data;lookup_row;component1_cols;component2_cols;result_col

法典:

=LET(
    sourceData; fxProcessVal(
        INDEX(data; lookup_row; 2);
        component1_cols;
        component2_cols;
        result_col
    );
    res_val; INDEX(data; 1; 1);
    res_col; IFNA(EXPAND(res_val; ROWS(sourceData)); res_val);
    sourceRes; HSTACK(res_col; DROP(sourceData; 0; 1));
    IF(
        sourceData <> "";
        FILTER(sourceRes; CHOOSECOLS(sourceRes; 2) <> "");
        CHOOSEROWS(data; lookup_row)
    )
)

http://www.ohchr.org。

参数:source;component1_cols;component2_cols;result_col

法典:

=LET(
    seq; SEQUENCE(ROWS(source));
    reducer; REDUCE(
        "";
        seq;
        LAMBDA(acc; curr;
            VSTACK(
                acc;
                IFNA(
                    fxProcessCompRow(source; curr; component1_cols; component2_cols; result_col);
                    HSTACK(""; ""; "")
                )
            )
        )
    );
    temp_res; DROP(reducer; 1);
    temp_res
)

<>strong>fxCompst:

参数:component1_cols;component2_cols;result_col

法典:

=IFNA(
    INDEX(
        unitprice_col;
        MATCH(
            MAXIFS(purchasedate_col; purchasedate_col; "<=" & date; purchasecomponent_col; comp) &
                comp;
            purchasedate_col & purchasecomponent_col;
            0
        )
    );
    0
)

<>prox>:

参数:seed;component1_cols;component2_cols;result_col

法典:

=LET(
    res; IF(
        COUNTA(seed) = 1;
        fxProcessVal(seed; component1_cols; component2_cols; result_col);
        fxProcessComp(seed; component1_cols; component2_cols; result_col)
    );
    comp; CONCAT(seed) = CONCAT(res);
    IF(comp; seed; prox(res; component1_cols; component2_cols; result_col))
)

参考:

“entergraph

Formulas

探索生物浓缩计划清单的方法(并按所需产品材料和数量分列):

=UNIQUE(DROP(REDUCE("";TableBOM[Resultado];LAMBDA(acc;curr;VSTACK(acc;prox(curr;TableBOM[[Componente 1]:[Q1]];TableBOM[[Componente 2]:[Q2]];TableBOM[Resultado]))));1))

“entergraph

每一产品成本的计算日期采用这一公式,在幅度内动态确定:

=DATE(YEAR(Q1);SEQUENCE(1;DATEDIF(Q1;Q2;"M")+1;MONTH(Q1);1);1)

“entergraph

STUCKED HERE:

我想确定Q3(时间范围作为溢出范围),计算每个月每个产品的费用。

目前,预防母婴传播中心计算了所有几个月的总数(时间范围)。

我曾接受过《圣经》的审判,并结合了《巴塞莫行动计划》和《圣经》,但已经表明了这一点。

如果有任何帮助,我将不胜感激。

Link改为只读样(无宏观)

=LET(
     data;L4#;
     date;Q3#;
     res;INDEX(data;;1);
     comp;INDEX(data;;2);
     q;INDEX(data;;3);
     lab;UNIQUE(res);
     cost;q*fxCompCost(comp;date);
     rt;MAP(lab;LAMBDA(a; SUMPRODUCT((res=a)*cost)));
     temp;HSTACK(lab;rt);
temp
)

“entergraph

预期成果:

“entergraph

问题回答

我将<代码>REDUCESE RequestNCE合并到每一日栏。

=LET(
     data;L4#;
     dateRow;DATE(YEAR(ParamStartDate);SEQUENCE(1;DATEDIF(ParamStartDate;ParamEndDate;"M")+1;MONTH(ParamStartDate);1);1);
     headers;HSTACK("";dateRow);
     date;dateRow;
     res;INDEX(data;;1);
     comp;INDEX(data;;2);
     q;INDEX(data;;3);
     lab;UNIQUE(res);
     cost;q*fxCompCost(comp;date);
     reducer;REDUCE("";SEQUENCE(COLUMNS(date));LAMBDA(acc;curr;HSTACK(acc;MAP(lab;LAMBDA(a; SUMPRODUCT((res=a)*CHOOSECOLS(cost;curr)))))));
     result;VSTACK(headers;HSTACK(lab;DROP(reducer;;1)));
     result
)

列入工作表格的名称:

ParamStartDate: Q2 ParamEndDate: Q3

Final:

“enterography

如果有人提出更好的解决办法,甚至处理管理局,请将其职位上调。

希望有助于其他人。





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...