I saw the following question on here regarding repeating values: List number of lessons including half lessons based on Number of lessons and lesson name
This question needed an older Excel version, I liked the problem statement and liked searching for a solution including new Excel formulas.
We have the following data:
A | B | |
---|---|---|
1 | 1 | w |
2 | 5 | e |
3 | 4.5 | o |
4 | 2.5 | Win |
5 | 1.5 | pp |
The idea is to repeat the value of column B the number of times mentioned in column A.
The challenge is that column A could also contain non-integers (0.5
-values only).
If a 0.5
-value is used it should repeat the value in column B the number of integers in A and show 0.5
and the text value stacked with 0.5
and the next text value.
In this case the expected result would be:
expected |
---|
w |
e |
e |
e |
e |
e |
o |
o |
o |
o |
0.5 o, 0.5 Win |
Win |
Win |
pp |
0.5 pp |
I managed to get a working solution in Office 365:
=LET(
data,A1:B5,
A,INDEX(data,,1),
B,INDEX(data,,2),
s,SCAN(0,A,LAMBDA(a,b,a+b)),
si,INT(s),
sr,ROUNDUP(s,0),
sm,SEQUENCE(MAX(sr)),
mr,XMATCH(sm,sr,1),
mi,XMATCH(sm,si,1),
IFERROR(
IF(mr=mi,
INDEX(B,mr,),
"0.5 "&INDEX(B,mr,)&", 0.5 "&INDEX(B,mi)),
"0.5 "&INDEX(B,mr,)))
and Tony got an answer using FILTERXML coming real close in the original question:
=FILTERXML(REPLACE(CONCAT(REPT("</c><c>" & B2:B6,FLOOR(A2:A6,1)) & IF(A2:A6-INT(A2:A6)>0,"</c><c>" & A2:A6-INT(A2:A6) & B2:B6,"")),2,2,"p")&"</c></p>","//c")
Would this be realisable in Excel 2013?