Skills Advisor

Retrieve Previous Step Output in DAX

This guide explains how to use DAX functions like `LOOKUPVALUE` and variables to retrieve the output from a previous calculation step based on the current step's input in a data analysis context.


Empty image or helper icon

Prompt

Dear Sir/ Madam,I am trying to get the previous output for my latest input for each step.As you can see from the table above, for step no 80, the input needs to be 90 as the output from step 70 is 90.Is there a DAX formula that can do thisSample Data for Input and Output.pbix (51.5 KB)Sample Operation Overview.xlsx (12.2 KB)?Thanks.

Answer

Analyzing the Problem

You need to retrieve the output from the previous step based on the current step's input. Specifically, for step number 80, the output must match the input of 90, which comes from the output of step 70.

To achieve this in DAX, you can leverage functions that allow you to reference previous rows or steps effectively. This typically involves the use of LOOKUPVALUE, FILTER, or similar functions that allow you to create a relationship between the steps based on their order.

DAX Solution

Here is a sample DAX formula that can accomplish your goal. This formula will create a calculated column that retrieves the output from the previous step based on the current step's input.

PreviousStepOutput = 
VAR CurrentStep = 'Table'[Step]
VAR PreviousStep = CurrentStep - 10 -- Example assuming each step is 10 units apart
RETURN
    LOOKUPVALUE(
        'Table'[Output], 
        'Table'[Step], 
        PreviousStep
    )

Explanation

  • Variables:

    • CurrentStep holds the value of the current row's step.
    • PreviousStep calculates the step number you're interested in (assuming each step is 10 units apart, adjust accordingly).
  • LOOKUPVALUE: This function retrieves the 'Output' from the previous step where the 'Step' matches PreviousStep.

Best Practices

  1. Use Variables: Utilizing variables like CurrentStep and PreviousStep enhances readability and performance.
  2. Testing: Validate the DAX formula by creating a sample table to ensure it retrieves outputs correctly for various steps.
  3. Documentation: Maintain clear documentation of any formulas you create for future reference and collaboration.

Conclusion

This DAX approach efficiently retrieves previous step outputs based on the current input conditions. If you require more complex interactions or additional scenarios, consider exploring Enterprise DNA’s resources for DAX courses, which can enhance your understanding of data analysis techniques using appropriate language.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This guide explains how to use DAX functions like LOOKUPVALUE and variables to retrieve the output from a previous calculation step based on the current step's input in a data analysis context.