Forum Discussion
fitconsulting
7 years agoFrequent Visitor
VALORATED CONSUMPTION
I’m having trouble getting a query, could you please help me? I have one first table with monthly stock consumption per product (CONSUMPTION TABLE). I also have another table with monthly pur...
- Anonymous7 years ago
While I think DAX can work for something like this, seems like Power Query is better tool for this job.
- Load your data tables, I named them as Purchases and Consumption
- Create two "Setup" Tables:
- There are two: AllMonths and AllArticles
- You can see the applied steps of each, but basically it appended both the data tables and some transformations to ensure we have all the available months and all the available articles
- We then did a full merge of the two setup tables. You will see that I added a custom column in each of the lookup tables of just "1". When doing a full merge based on that, we are really generating the cartesian product. Be sure to that months are sorted correctly (there was a column added for that)
- Then merged that table with the Consumption table to get the "Cost" column, which will generate some nulls ( and this is a good thing! )
- Next, group the rows by Article, and we want all the rows. This will produce a table for each Article with all the available months and cost. If you click in cell (not the actaul text) you will see
- Since the months are sorted correctly, we can fill down in each sub-table. So if there is a null it will pull down the previous value
- Then we can remove all the other columns, except the column with the new table. Expand that table
- Merge that table with the Consumption table to get the "Stock Consumption" figure. There will be nulls and that is ok
- Add a column to multiply those together
- Filter out the nulls and set data type.
Here's your final output that will work when you add in new months and articles:
Much easier to see in PQ and the applied steps. Here is the excel file:
Anonymous
7 years agoNot applicable
Where does the February, Article B Unitary Cost of -3 come from? That field ( and a few others) doesnt exist. Is there some more logic there or is there missing data?
- fitconsulting7 years agoFrequent Visitor
because product B does ot have values for February, so it maintains the value of January