Yes, I know, the question sounds crazy but I don't know how else to explain it; the context is as follows, I am trying to make an indicator of the number of product records between a line and a state ("Line" is an example) where each line has several states but I need that indicator to attach the total number of records per line without count the states, the number of by-products and the total of products and by-products; These are two independent tables and I want everything to be in a single "query".
For practical purposes, I will only exemplify only two states, "in progress" and "finished" and for lines I will leave "assembly" and "packaging".
AddColumns(
LineTable,
"states", AddColumns(
Table(
{ state: 1, name: "In progress" },
{ state: 2, name: "Finished" },
{ state: 97, name: "FirstTotal" },
{ state: 98, name: "By-products" },
{ state: 99, name: "GeneralTotal" }
) As States,
"total", Switch(state,
98, CountRows(
ByProductsTable,
state in [1, 2]
),
99, 0, // Here should go the sum of those two records
CountRows(
ProductsTable,
If(state <> 97,
state = States.state,
state in [1, 2]
)
)
)
)
The question is, how to make the states 97 and 98 add up inside the AddColumns of the "States" column of the lines, in other words, that this sum remains in the state 99.
I found a solution but it is not what I wanted and it is to create redundancy with the total of states per line plus the number of by-products but I don't think this is efficient.
AddColumns(
LineTable,
"states", AddColumns(
Table(
{ state: 1, name: "In progress" },
{ state: 2, name: "Finished" },
{ state: 97, name: "FirstTotal" },
{ state: 98, name: "By-products" },
{ state: 99, name: "GeneralTotal" }
) As States,
"total", Switch(state,
98, CountRows(
ByProductsTable,
state in [1, 2]
),
// ineffective solution (?)
99, CountRows(
ProductsTable,
state in [1, 2]
) + CountRows(
ByProductsTable,
state in [1, 2]
),
// ------
CountRows(
ProductsTable,
If(state <> 97,
state = States.state,
state in [1, 2]
)
)
)
)
The other possibility is to make the internal gallery, in the label, show the sum of those two records using the LookUp function and calling the corresponding records to make that sum, but I feel that what I propose can be done but it does not occur to me how to do it.