Forum Discussion
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 Range | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| Month - Year | Nov-18 | Oct-18 | Sep-18 | Aug-18 | Jul-18 | Jun-18 | May-18 | Apr-18 | Mar-18 | Feb-18 | Jan-18 | Nov-17 |
| FRCAST | 71.59 | 60.54 | 51.36 | 51.36 | 51.36 | 51.36 | 51.36 | 51.36 | 51.36 | 51.36 | 19.35 | 21.41 |
| RECEIPTS | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| GROSSUSG | 91 | 151 | 59 | 0 | 84 | 74 | 125 | 123 | 106 | 98 | 54 | 85 |
| Turn-Ins | 0 | 400- | 100- | 0 | 0 | 0 | 0 | 0 | 0 | 600- | 0 | 0 |
| QOH-EOM | 173 | 290 | 41 | 0 | 0 | 84 | 158 | 283 | 406 | 512 | 10 | 64 |
7 Replies
- Ashish_MathurSuper User
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_RomHelper 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_MathurSuper User
Hi,
Click on New Table and write this formula
Calendar=CALENDER(DATE(2017,1,1),DATE(2018,12,31))
- v-piga-msftResident 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_RomHelper 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 # Date Transactions Value 7788 12/1/2017 Frcast 1.25 7788 12/1/2017 Receipts 500 7788 12/1/2017 Turn-Ins 100- 9856 3/1/2018 Receipts 300 9856 3/1/2018 Frcast 2 9856 3/1/2018 Receipts 600- 4598 5/1/2018 Grossusg 700- 4598 5/1/2018 Receipts 400 1235 11/1/2018 Receipts 300 1235 11/12018 Grossusg 150