Forum Discussion

msellner_1025's avatar
3 years ago
Solved

Use Result of Query 1 in Query 2

Hello!  

 

I have a query that returns a random file name that I need in order to download a csv formatted reported. Below is the power query that I have set up – it returns the file name as expected and is working great! 

 

The result is always one value in the first row/column (see example screenshot below). 

 

I need to run a second query that uses the random file name generated from the first query. Currently, I am manually pasting this value into the second query after I run the first query and it returns the random file name. Below is the second query I am using – I highlighted the variable value that I paste in from query one. 

 

 

How can I set up the second query so that it will use the result of the first query and not require me to paste in the new random file name value each time? 

 

Thank you!

  • jbwtp's avatar
    jbwtp
    3 years ago

    Hi msellner_1025,

     

    According to the format of what you say works the line should look like:

     ""fileName"":""" & Expensify_PullDataRequest & """

    Otherwise you either missing the "" ( ""fileName"":Expensify_PullDataRequest) or send Expensify_PullDataRequest as value instead of  is_reconciliation_2816079167651847981.csv.

     

    Cheers,

    John

14 Replies

  • Hi msellner_1025 ,

     

    Right-click on your random file name cell and select 'Drill Down'. This will convert your table value into just a floating value.

    At the start of your second query, declare this as a variable using just

    'variableName = nameOfRandomFileNameQuery'.

    Then you should be able to apply this variable in your code instead of the hard-coded file name.

     

    Pete

     

  • BA_Pete,

     

    Thank you in advance for your help!

     

    How do I reference the floating value? I think my code is applying the variable incorrectly as I get an error message when I run it now.

     

    Thanks!

      • msellner_1025's avatar
        msellner_1025
        Helper I

        BA_Pete,

         

        Thank you for your help! The format """ & Expensify_PullDataRequest & """ worked! So happy to have this figured out!

         

        Thank you,
        Mikail

         

    • BA_Pete's avatar
      BA_Pete
      Super User

       

      It may be because you surrounded it with curly braces ( { } ). Try using it just as ""fileName"":"csvFile"

       

      Pete