Share via

Reduce indirect and Vstack

Anonymous
2024-04-27T12:23:13+00:00

I hope this makes sense using reduce ;

REDUCE( INDIRECT( TAKE( Table13[Store],1)), DROP(Table13[Store],1), LAMBDA(s,c, VSTACK(s, INDIRECT( c ) )))

This works, but if you chang slightly so indirect is used only in the vstack;

REDUCE( TAKE( Table13[Store],1), DROP(Table13[Store],1), LAMBDA(s , c, VSTACK( INDIRECT( s ), INDIRECT( c ) )))

so indirect is used in vstack for both it fails, unless I'm making some stupid typo / error any ideas why this should happen ?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2024-04-27T13:10:38+00:00

Hello RichardDrake1505,

* I am a Microsoft user like you, providing solutions to community members; I am NOT a Microsoft employee.

The reason your formula breaks when using INDIRECT inside VSTACK twice is because LAMBDA captures the value of s and c at the time the function is defined, not when it's called within REDUCE.

Here's how you can fix it:

Option 1: Use INDEX Instead of INDIRECT Instead of INDIRECT, use INDEX to reference the elements within Table13[Store]. This approach relies on the actual positions of s and c within the table:

REDUCE(TAKE(Table13[Store],1), DROP(Table13[Store],1), LAMBDA(s,c, VSTACK(INDEX(Table13[Store], s), INDEX(Table13[Store], c))))

Option 2: Use a Nested LAMBDA You can use a nested LAMBDA function within your main LAMBDA to access the current values of s and c during each iteration of REDUCE:

REDUCE(TAKE(Table13[Store],1), DROP(Table13[Store],1), LAMBDA(s,c, VSTACK( LAMBDA(x, INDIRECT(x)) (s),
LAMBDA(x, INDIRECT(x)) (c) ) ) )

Hope this helps.

  • Stephen N.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2024-04-27T14:57:40+00:00

    Yes it does work.

    if you have any queries please direct them to victor;

    (29) Reduce function in excel to stack tables with VSTACK - YouTube

    Richard

    Was this answer helpful?

    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Anonymous
    2024-04-27T14:09:22+00:00

    Thanks, very thorough, so it is similar to when you declare a variable for a DAX measure?

    RD

    Was this answer helpful?

    0 comments No comments