The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello dear community,
I would like to sum up past values in a line chart in order to be able to calculate the stock level. Unfortunately, I can't get the value from the previous months to add up.
As you can see, the stock in May should be 89 (stock from April) - 126 sales + 68 returns (not shown in the picture) = 31 and not -126.
I hope you understand my problem.
I have already tried several formulas and just don't know what to do. Many thanks in advance for your support.
LG
Solved! Go to Solution.
Hi @LovePowerBi1994
Please try this measure
Stock =
VAR CurrentDate =
MAX ( vw_Zeit[Date] )
VAR T1 =
ADDCOLUMNS (
ALLSELECTED ( vw_Zeit[Date] ),
"@Sales", CALCULATE ( SUM ( Sales[Sales] ), Sales[ReturnYesorNo] = "No" ),
"@GoodsRecieved", CALCULATE ( SUM ( 'goods receipt'[Goods Recieved] ) ),
"@Returns", [Returns],
--assume [Returns] is a measure?
"@Shortages", CALCULATE ( SUM ( Shortages[quantity] ) )
)
VAR T2 =
FILTER ( T1, vw_Zeit[Date] <= CurrentDate )
RETURN
SUMX ( T2, [@GoodsRecieved] - [@Sales] + [@Returns] - [@Shortages] )
If you are working at Month-Year level the following would be much more efficient
Stock =
VAR CurrentDate =
MAX ( vw_Zeit[Date] )
VAR T1 =
ADDCOLUMNS (
ALLSELECTED ( vw_Zeit[Month-Year] ),
"@Sales", CALCULATE ( SUM ( Sales[Sales] ), Sales[ReturnYesorNo] = "No" ),
"@GoodsRecieved", CALCULATE ( SUM ( 'goods receipt'[Goods Recieved] ) ),
"@Returns", [Returns],
--assume [Returns] is a measure?
"@Shortages", CALCULATE ( SUM ( Shortages[quantity] ) )
)
VAR T2 =
FILTER ( T1, vw_Zeit[Date] <= CurrentDate )
RETURN
SUMX ( T2, [@GoodsRecieved] - [@Sales] + [@Returns] - [@Shortages] )
yes exactly. It means Stock.
Are all columns coming from the same table? If not would you please advise the the details of your data model and relationships?
In case you are using a date table please try
Stock =
VAR CurrentDate =
MAX ( 'Date'[Date] )
VAR T1 =
ADDCOLUMNS (
ALLSELECTED ( 'Date'[YearMonth] ),
"@Sales", CALCULATE ( SUM ( TableName[Sales] ) ),
"@Goods Received", CALCULATE ( SUM ( TableName[Goods Received] ) )
)
VAR T2 =
FILTER ( T1, 'Date'[Date] <= CurrentDate )
RETURN
SUMX ( T2, [@Goods Received] - [@Sales] )
Thank you
Hi @tamerj1
thanks for the quick reply.
In total, the information comes from 4 tables.
There is one time table
A table with goods receipt information.
A table with sales and returns.
and a table with shortages.
To illustrate this, I have attached a brief outline of the data model.
The formula is:
Goods Receipts - Sales + Returns - Shortages.
I have tried to adapt the formula. Unfortunately, I was only shown the current stock across all months and not the stock that was valid for the respective month.
Enclosed is my attempt at adjustment. I have already created a measure for calculating the stock.
Formula of the measure "Bestand"
=
like this?
Which column are you using in the x-axis? Please use the Month-Year column from the date table.
it works! thank you very much! I took the first formula you mentioned and adjusted the x axis with MonthYear.
Now I just have to find a way to sort the x axis correctly.
Thank you thank you thank you!
Hi @LovePowerBi1994
Please try this measure
Stock =
VAR CurrentDate =
MAX ( vw_Zeit[Date] )
VAR T1 =
ADDCOLUMNS (
ALLSELECTED ( vw_Zeit[Date] ),
"@Sales", CALCULATE ( SUM ( Sales[Sales] ), Sales[ReturnYesorNo] = "No" ),
"@GoodsRecieved", CALCULATE ( SUM ( 'goods receipt'[Goods Recieved] ) ),
"@Returns", [Returns],
--assume [Returns] is a measure?
"@Shortages", CALCULATE ( SUM ( Shortages[quantity] ) )
)
VAR T2 =
FILTER ( T1, vw_Zeit[Date] <= CurrentDate )
RETURN
SUMX ( T2, [@GoodsRecieved] - [@Sales] + [@Returns] - [@Shortages] )
If you are working at Month-Year level the following would be much more efficient
Stock =
VAR CurrentDate =
MAX ( vw_Zeit[Date] )
VAR T1 =
ADDCOLUMNS (
ALLSELECTED ( vw_Zeit[Month-Year] ),
"@Sales", CALCULATE ( SUM ( Sales[Sales] ), Sales[ReturnYesorNo] = "No" ),
"@GoodsRecieved", CALCULATE ( SUM ( 'goods receipt'[Goods Recieved] ) ),
"@Returns", [Returns],
--assume [Returns] is a measure?
"@Shortages", CALCULATE ( SUM ( Shortages[quantity] ) )
)
VAR T2 =
FILTER ( T1, vw_Zeit[Date] <= CurrentDate )
RETURN
SUMX ( T2, [@GoodsRecieved] - [@Sales] + [@Returns] - [@Shortages] )
with the first part i get the same results.
The second one diddnt worked and caused an error.
but the first Solution works fine for me. Thank you!!! you helped me a lot!
User | Count |
---|---|
16 | |
8 | |
6 | |
6 | |
5 |
User | Count |
---|---|
23 | |
13 | |
13 | |
8 | |
8 |