Forum Discussion

Angela_Rom's avatar
Angela_Rom
Helper I
7 years ago

How to create query using data from existing tables in Power Query Editor

Hello Everyone,

 

I am trying to create a 12 month view for five groups of data located in five different tables. The issue I am having is that I need the 12 month view to be created in order to tie in all the data to the date which is Month/ Year format.  I was thinking of creating a blank query with Month Range listed as 1-12 and bring in all the data. Below is what I would like the table to look like. I want to arrange the month date by descending order and show only a 12 month view. I think for each column, I must create a formula for each column. What type of formula would I need to create to tie each month with the date range?

 

 

Date Range123456789101112
Month - YearNov-18Oct-18Sep-18Aug-18Jul-18Jun-18May-18Apr-18Mar-18Feb-18Jan-18Nov-17
FRCAST71.5960.5451.3651.3651.3651.3651.3651.3651.3651.3619.3521.41
RECEIPTS000000000000
GROSSUSG911515908474125123106985485
Turn-Ins0400-100-000000600-00
QOH-EOM1732904100841582834065121064

 

 

7 Replies

  • Hi,

     

    Create a Calendar table and build a relationship from the Date column of each of the 5 different tables to the Date column of the Calendar Table.  In the Calendar Table, write these calculated column formula to extract Year and Month

     

    Year=Year(Calendar[Date])

    Month=FORMAT(Calendar[Date],"mmmm")

     

    Create another 12 rows by 2 column table with Month names mentioned in range A2:A13 and numbers (in descending order from 12 to 1) in range B2:B13 (This Table is named Month_Order and the column headings are Month and Order).  Create a relationship from the Months column of the Calendar Table to the Month column of this Table.  In the Calendar Table, write this calculated column formula

     

    =RELATED(Month_Order[Order])

     

    Now click on any cell in the Month column of the Calendar Table and under Sort By column, select Order.

     

    Build your Matrix visual by dragging Year and Month from the Calendar Table to the Column headers.  Write measures to get the figures.

     

    Hope this helps.

    • Angela_Rom's avatar
      Angela_Rom
      Helper I

      Hi Ashish,

       

      Would I create the calendar table using Dax or do I create this as a query editor?

       

      Thank you too for your response.

       

      Regards,

      Angela

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

         

        Click on New Table and write this formula

         

        Calendar=CALENDER(DATE(2017,1,1),DATE(2018,12,31))

  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi Angela_Rom,

     

    If I understand your requirement correctly that the table above is your desired output? If it is, more details would be better. 

     

    If it is convenient, please share your sample data which could reproduce the scenario such as the five different tables so that we could help further on it.

     

    Best  Regards,

    Cherry

    • Angela_Rom's avatar
      Angela_Rom
      Helper I

      Hi Cherry,

       

      Yes, the table above is my desired output. Below is the query I created. First, all the five tables were appended into one query using the Frcast data as the starting point. Then I grouped all transactions to produce the values as well as create a conditional column to create the different transactions. 

       

      The issue that I encountered by using the Frcast table as the starting point is that if a part number is not in the frcast query then I will not receive any data. I need the format to look like the table above and if there is no value than zero should populate for any of the transactions.  This is when I realized that I need to tie my data using a date table so that data can be shown based on a 12 month view regardless of the value.  Below is the list of the consolidated query with the appended five tables.  Please let me know if you have any questions about the inforrmation. Thank you too for your help.

       

      Part #DateTransactionsValue
      778812/1/2017Frcast1.25
      778812/1/2017Receipts500
      778812/1/2017Turn-Ins100-
      98563/1/2018Receipts300
      98563/1/2018Frcast2
      98563/1/2018Receipts600-
      45985/1/2018Grossusg700-
      45985/1/2018Receipts400
      123511/1/2018Receipts300
      123511/12018Grossusg150