Hi - so the category of your question would be "combinatorics" which is most related to this forum's "probability and statistics" sub-forum.
That these 3D cubes are arranged in a cube is not necessary for finding a formula. What we need is the total number of 3D cubes, which when you take the product of the length, width, and depth of your cubes' arrangement, is the number we will be working with. For your example, you use 2*2*2 = 8 3D cubes. The formula we create will be expandable to any number of cubes.
Now, in your examples section you do something unique that needs to be resolved - Do you OR do you not count '0' as a possible outcome of any of the 8 cubes? Let me revise your examples as if '0' is allowed as a possible outcome.
"
for the first cube position, there are 3 possibilities
0
1
2
if I use 2 cube positions, I would have 9 possible combinations
1 - 0
1 - 1
1 - 2
2 - 0
2 - 1
2 - 2
0 - 0
0 - 1
0 - 2
"
I bring this nuance up because in your example involving 2 cube positions, you included some 0's as if that was a possible outcome on any one of the 8 cubes.
If you do NOT allow 0's as a possible outcome, your examples would be written as
"
for the first cube position, there are 2 possibilities
1
2
if I use 2 cube positions, I would have 4 possible combinations
1 - 1
1 - 2
2 - 1
2 - 2
"
In summary, if you allow '0s' to be counted, you have 3 possibilities for each cube.
If you don't allow '0s' to be counted, you have just 2 possibilities for each cube.
Let's assume you are allowing '0' as a possible outcome for any given cube position and go from there.
=====================================
Counting the Possibilities:
For the 1st cube in the set of 8, you have (0,1,2) -> 3 possibilities
For the 2nd cube in the set of 8, you have (0,1,2) -> 3 possibilities
For the 3rd cube in the set of 8, you have (0,1,2) -> 3 possibilities
...
For the 8th cube in the set of 8, you have (0,1,2) -> 3 possibilities
Ah ha! So by simply observing that each cube in the set of 8 can produce 1 of 3 different outcomes, namely '0' '1' or '2' we know that there are 3*3*3*3*3*3*3*3 = 3^8 = 6,561 possibles outcomes or 'states' when considering those 8 cubes. 3^8 is read as "3 to the power of 8" and just means to multiply 3 by itself 8 times.
6,561 is a lot of possibilities!
But what if you change the number of cubes?
Instead of 8, maybe 27.
What if you change the size of the set of things that could appear on any of those cubes?
In other words, maybe you want more than just '0' '1' or '2' to be a possible outcome on any given cube. Maybe you want '4' '9' 'yes' 'no' or 'maybe'. In this made up set of possible outcomes, you would be dealing with 5 possible outcomes instead of your original 3.
=====================================
We are going to find a general formula now.
First, find the total number of 3D cubes you will be using by using the product of length*width*height.
Let's call this number C (for cubes)
C = length* width* height
Now, ask how many outcomes each cube can have. '0' '1' or '2' equates to 3 possible outcomes but for whatever you choose, you need to count those possible outcomes. Let's call this number of possible outcomes P (for possibilities)
And here is the general formula:
P^C = total number of combinations
"P to the power of C is the total number of combinations."
=====================================
An example using the general formula;
If your matrix of cubes 3D cubes has 4 rows, 4 columns, and 6 columns deep, we then know C is
C = 4*4*6 = 84
If each cube can have a '1' or a '2' as a possible outcome (no '0' this time), then we know P = 2 because there are 2 possibilities for each cube.
Therefore, the total number of combinations is simply,
P^C = 2^84 = about 19,000,000,000,000,000,000,000,000
That's a ridiculous number of combinations!