values calculated from all previous rows - recursion

Entries =
a single value corresponding to an initial stock of goods (eg. 5)
an excell file with three columns
-- date
-- a production of goods for that date (eg. 10)
-- a request for goods for that date (eg.20)
I need for each date to calculate =
the sold quantity = minimum [stock on previous date + production ; request]
(in the eg.15)
the new stock = previous stock + production - sold quantity
(in the eg. 0)
On next date a new calculation based on new production and new request is to be done.
I have no problem to do in the Excell sheet but I cannot manage to do it integrating the entry file with Dax.
Thanks a lot for ideas you may have.
I tried Dax formula to get data from the date before it works.
But the trick here is the stock for a date depends on sold quantity and stock from all previous dates.

Related

SQLiteStudio automatically insert value

I have a database created with SQLiteStudio that has a products table with two columns, item and price. It also has a sales table with an item column that is linked to the item column in products. I'd like the sales table to also have a price column, whose value is automatically set to that of the products.price row corresponding to the value selected from the products.item column. How would I define the sales.price column so that this value is automatically set?
Also, the prices in the products table may be changed from time to time, but the price listed in any existing sales records must not be updated when this is done.
SQLite has generated columns (also called expression columns) that are found in other DBMSes. But you'll need a fairly recent version of SQLite:
Generated column support was added with SQLite version 3.31.0
(2020-01-22). If an earlier version of SQLite attempts to read a
database file that contains a generated column in its schema, then
that earlier version will perceive the generated column syntax as an
error and will report that the database schema is corrupt.
Source: Generated Columns
You could simply build a view to augment your table a little bit.
You have mentioned that the prices will change over time and this is perfectly normal. So you have at least two design choices:
add an additional table to store price history, in that table you store product ID, price, start date and end date (as an example). Then you join it with the other tables. The effective price shall be determined based on the order date. That also means that the prices are to be stored in that table and not in products... you have to redesign your schema slightly.
the other option is to store the unit price of the product in the sales table as a historical value. This is the price that was in force when the sale was made.
One thing to consider: you may require more flexibility on pricing: it can depend on the client (different rates based on volume) and also on specific circumstances. The final price may be the result of numerous and complex calculations.

Power BI - How do I get the Status correct based on the columns I add or remove

Am stuck in a situation that I cant seem to solve, still learning so would appreciate if you could tell me what am I doing wrong and how do I get this right? It seems simple, but not for me anymore.
Background:
ACME company sells products in various cities and I need to check if ACME is Cheaper, Same or Expensive in terms of pricing. The same product may be sold in 10 different stores in a city and we want to know:
How is ACME doing for each product by City or by Store and I
calculate that as follows:
For each City:
List all the instances of that one product (lets say that product was sold in 10 stores in Dallas,so 10 instances,which means we may have 10 different store prices
Then return the minimum price of these 10 prices
Compare this minimum price against the ACME price and determine whether the product is Cheap, Same or Expensive
Formula:
Measure to calculate min price = 1 Min Price = CALCULATE(MINX(Data,Data[Store Price]),ALLEXCEPT(Data,Data[Barcode],Data[City],Data[Match Type],Data[Store]))
Calculated Column to detrmine status = 2 Price Status = if(Data[ACME Price]<[1 Min Price],"Cheap",if(Data[ACME Price]=[1 Min Price],"Equal","Expensive"))
Problem to be solved:
Screenshot 1 - When i have stores listed along with City, then the formula should consider the Store column and give me minimum price per Store (basically it will do a row by row comparison as a a store will show only once per city) which is what its doing in the "Min Price" and also the status is correct
Screenshot 1 - With Stores
[
Screenshot 2 - When I remove stores, the "Min Price" column is showing the right minimum price for a product per city, however the Status is incorrect - for product ending 7572, both the status must be Equal and for product ending 3566, it should be Expensive
Screenshot 2 - Without Stores
Can someone please advise what am I doing wrong? How do i get the status right when viewing by City?

Find observations of an ID within a certain timeframe in the future in Tableau

I have a dataset in Tableau that contains sales data listing each sale the company has had in the past year. Each customer has a unique ID, and many customers return. I'm trying to figure out how to create a calculated field in Tableau that gives a True | False answer to whether a given patient ID appears again in the dataset within a given timeframe (say, within six weeks of a given observation).
I've tried running it with LOOKUP, but I haven't been able to specify the increase in time effectively.
This would be how I would approach it. Create two date parameters, start and end.
Then create a filter calc for the date.
[date] >= [param_date_start]
and
[date] <= [param_date_end]
Place this in the filter shelf set to TRUE.
Then create another parameter for your customer id and you can test for the existence of a customer id as follows.
max([customer_id] = [param_customer_id])
This will return true if there is at least one record where the customer_id equals the param_customer_id for the chosen dimensions and date range.
You could use this same approach to define a computed set, say the set of all products that were purchased by the customer in the specified date range, or the set of all patients that received a particular service. Just use this formula on the condition tab when defining the set.

Rate issue in Trade agreement journal

I have created multiple journals for an item (suppose "item1") in AX2012 with multiple rates and different from and to date.
Like for Journal 1, From date is set as 1/12/2013 and to date is NULL and rate as 50.
for journal 2, From date is set as 7/12/2013 and to date is NULL and rate as 60.
Now, logically when selecting item in sales line form on or after 07/12/2013, I must get unit price 60. But unit price that i am getting is 50.
How to get latest price of an item, account, to, from date in sales line form?
It is valid in AX to have more than one active price record (PriceDiscTable).
In your case both 50 and 60 are valid rates, it then does the service of choosing the lesser one!
In journal 2 you should find the old rate, then apply an end date of 06/12/2013.
As this is cumbersome, it is a usual customization to auto-close prices. This could be done in the insert method of PriceDiscTable.

Formula for conditional count of data with criteria in two different columns

My spreadsheet records every customer encounter and what employee they see the day of the visit. There are also two columns for whether they make a same day payment or make a payment on their account balance. I need a formula that will not only count how many customers an employee sees but only counts the customers that make same day payments.
Column B has the employee's initials listed in a drop down, so I will need the formula for each employee. Column F is the column for same day payments.
If it helps, each row collects an array of information: customer last and first name, phone number, employee who helped them, same day payment, balance on account payment, and payment method. I'm trying to count how many customers are coming in and making same day payments. I need to separate it by employee for commission reasons.
I have tried:
=COUNTIF('1'!B:B,"BK")
B is the column the employee names are in and BK is one of the employees. This formula is counting any rows with BK and what I want it to do is ONLY count the rows where a "same day" payment has been made (this is column F).
Assuming this is Excel, because you need an answer for a number of employees I strongly recommend a PivotTable, therefore with your columns labelled in Row1, Employee for ROWS and Count of "same day" for VALUES.
However if you prefer a formula, assuming ColumnF contains same day to indicate the same day payments an example for employee BK:
=COUNTIFS(B:B,"BK",F:F,"same day")
If you just need to count for all employees (so column B not blank) where there is a value in column F (greater than 0) you could just use:
=COUNTIFS($B:$B,"<>"&"",$F:$F,">"&0)
Or the following will count all cells in column F that arent blank:
=COUNTIF($F:$F,"<>"&"")

Resources