Power Query - FIFO Inventory Valuation - excel

We had experienced a problem with our inventory valuation in DAX, as we got a circular dependency. As DAX is not capable of recursion, we are pretty sure to solve this problem with power query functions.
Problem is the following:
Assuming i start with an initial stock: QTY 900000, Price 0,3 and I also have my monthly Sales QTY and Purchase QTY and price I could create the following (the Excel with the formulas for 2 months is attached)
Then, in the next month I would "just" need to take my closing inventory price as my opening price.
This is where the problem sits as it would need to be calculated first and then referencing itself while defining the formula like so:
openingunitrate=
if "initialstockunitrate"=blank() then
inventoryfromopening(monthyear-1)*openingunitrate(monthyear-1)+
inventoryfrompurchases(monthyear-1)*purchaseunitrate(monthyear-1)
/
closingstock(monthyear-1)
else
"initialstockunitrate"
Also what would need to be done is a grouping per "Category" and the column compliance_year. It should start in the next year with 0 as we only have an initial stock this year.
I don't know if this will actually require a recursive function in PowerQuery, so if you have any other idea how to solve it, it's fine as well! In my head this logic totally makes sense but as I have little experince with PQ I'm struggling to actually code it there.
I attached an Excel file that includes both the calculation done in Excel and the sample data which would need to be enhanced.
Please find it under the following link:
Sample Data
thanks and regards,
Martin

Related

Formula or function for getting salesperson monthly sales average

Salesperson
JANUARY
FEBRUARY
SALES TYPE 1
'=January Ave
'=February Ave
SALES TYPE 2
'=January Ave
'=February Ave
I need help figuring out what formulas/nested functions I would use in the January and February average columns in the above table. The Excel document I'm working with has a tab for each sales person. In these tabs include the above table-like scorecard element.
I'm using the old "Sharing" feature of Excel which has a lot of limitations, you can't have tables in the document for example (experts, correct me if I am wrong about this) this is why I'm hoping to use a formula to get, calculate and input the data where it needs to go.
There is another tab where all the data is stored in a table-like structure. It has columns for the date of the sale, the ID of the sales person and how many sales were made on that day.
I'm also worried that too complicated of a formula being done 24 times in each sheet and there being a total of 50 sheets in the document, would this cause the document to lag? I'm reading on index match vs xlookup, I hear sumifs is easy but the file doesn't work as fast with that?
What formulas would you use? Any advice how to make sure the document runs smoothly when users use it? Any advice here is welcome. Thanks in advance for you patience.

Is there a way to sum data in Excel by group/category?

I'm completely new to Excel and am actually using it for the first time for a math paper, so I'm pretty lost to start with.
I have a large spreadsheet of data. It's organized in a table with the headers: country code, country name, date, and total. The dates range from April, 2020 to March, 2021 for 203 countries.
What I'm trying to do is to take the total amounts from each country each day.
I've included some screenshots from my excel spreadsheet:
Adding this data isn't so bad, right now I'm using the function =SUMIF(range, criteria (I'm just using ">0")). But when I have so much data to add, this feels really inefficient.
I was wondering if there was a function or if I could somehow create a function, that would let me input a country code and it would sum every row that has that country code? Or something similar that would speed up the process?
I'm sorry if this isn't the best-formatted question, it's my first time asking anything on Stack Overflow and I still new to the expectations from the community. Please let me know any extra information I can provide, ways I can clarify, or anything else.
Thank you to everyone in advance!
Depending on what you want to look at you can either use SUMIF / SUMIFS or a PIVOT table.
For your example above, I would recommend a PIVOT table. You can find further information on PIVOT tables here. Simply drag and drop the values you want to have in each row / column into the respective fields.
In case you then want the result to look nice, you can find information on formatting PIVOT tables here

Calculate average based on a value column (count) in a pivot table

I'm looking a way to add an extra column in a pivot table that that averages the sum of the count for the months ("Count of records" column) within a time period that is selected (currently 2016 - one month, 2017 - full year, 2018 - 5 month). Every month would have the same number based on the year average, needs to be dynamically changing when selecting different period: full year or for example 4 months. I need the column within the pivot table, so it could be used for a future pivot chart.
I can't simply use average as all my records appear only once and I use Count to aggregate those numbers ("Count of records" column).
My current data looks like this:
The final result should look like this:
I assume that it somehow can be done with the help of "calculated filed" option but I couldn't make it work now.
Greatly appreciate any help!
Using the DataModel (built in to Excel 2013 and later) you can write really cool formulas inside PivotTables called Measures that can do this kind of thing. Take the example below:
As you can see, the Cust Count & Average field gives a count of transactions by month but also gives the average of those monthly readings for the subtotal lines (i.e. the 2017 Total and 2018 Total lines) using the below DAX formula:
=AVERAGEX(SUMMARIZE(Table1,[Customer (Month)],"x",COUNTA(Table1[Customer])),[x])
That just says "Summarize this table by count of the customer field by month, call the resulting summarization field 'x', and then give me the average of that field x".
Because DAX measures are executed within the context of the PivotTable, you get the count that you want for months, and you get the average that you want for the yearly subtotals.
Hard to explain, but demonstrates that DAX can certainly do this for you.
See my answer at the following link for an example of how to add data to the DataModel and how to subsequently write measures:
Using the Excel SMALL function with filtering criteria AND ignoring zeros
I also recommend grabbing yourself a book called Supercharge Excel when you learn to write DAX by Matt Allington, and perhaps even taking his awesome online course, because it covers this kind of thing very well, and will save you significant head-scratching compared to going it alone.

Excel Index Function

I just want to thank you guys in advance. I think you guys are doing a great job in helping people out with programming stuff. Pats on the back for all of you.
Here is what I've been working on: I have daily stock price return data on about 4000 stocks. I want to add them to my portfolio after observing their performance for 12 months. I will choose the top 10% best performers and bottom 10% worst performers. I will create multiple portfolios over a period of time. I have done that with no problem.
I want to use the INDEX function to calculate the daily return of my portfolio. Not all 4000 stocks are in my portfolio, about 300 stocks are in my portfolio at any given time. The daily portfolio returns will be calculated by multiplying the weights (they are equal weighted, so 1/300) to that stock's return on the specific date. I assume it has to do with a combination of INDEX, SUMPRODUCT, and IF or MATCH functions.
I have been thinking this for a long time and I just can't get to the bottom of it. I have attached pictures for a portion of what I was working on. I think will give you a good picture of what I'm trying to do. I bet this is such an easy thing for you guys. I hope you can help me out! Thanks again!
PICTURES:IN or OUT portfolio & Stock's individual returns
Charles
Not sure I understood your problem, but here is a trial suggestion:
You get data for 4000 stocks while you are monitoring 300. So, you need to find the correct one within your sheet (there will be 3700 that will not match anything).
If you have your stocks listed in, say, column "A", you could use the function LOOKUP (well explained in the Web). If you need to get the row of your stock, you can use the function MATCH.
If this is not what you are looking for, it means that I (at least) did not understand you, so you would need to add details to your question.

Creating a sum based on a category within a date range

I'm trying to make a spreadsheet that I can easily take an export from Mint.com's CSV outputs and get them into my Excel budget.
To do so, I need a way to populate each field within a date range. I'd like to avoid macros if possible (I don't know how to make them).
I'm happy to share my finished .xls with the public!
I've imported Mint.com's data in a manner that has column S for the date (3/30), column V with the cash value that I need to add up, and column X for the spending category.
I need to tally each month's spending ($V) by category (column X).
Through research, I devised this (for my January "Gas & Fuel" spending):
=SUMIFS($W$2:$W$900, $T$2:$T$900, ">="&W$12, $T$2:$T$900, "<"&(EOMONTH(D$1,0)+1), $Y$2:$Y$900, "="&$B5)
However, it required that I reformat my Dates, which is an issue because this would become specific to each year and I would need to change the fields every year. I'd like the document to be usable without adjustment using my spending data from the past and future.
Is there a way to take the year out of the equation? To make that formula above work, I renamed my column from "January" to "1/14".
Here is what the spreadsheet looks like
Thanks!
A pivot table would work best with that data.
Initial set up would show each day separately, but by using Grouping
(here) ^^^
you can group the data by month/day/year/however

Resources