Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hy all
Greetings and thanks in advance.
I have a large data table in Data Model in excel 2016. This table is in SQL Server and is connected to Data Model in excel with Power Query. It has millions of rows. I have created pivot table report on it.
I need to calculate opening and closing stock for selected period (date, month or year). The sample of data is as given below. I am showing just a few columns and records in sapmle.
I have added 3 measures in the Pivot table fields.
1-Movement=calculate(sum('Table'[Qty]), 'Table'[In/Out]="In")
-calculate(sum('Table'[Qty]), 'Table'[In/Out]="Out")
It is working fine.
2-Opening Stock=calculate ( [Movement],
filter
(all ('Table'[Date] ),
'Table'[Date]<max('Table'[Date] )))
3-Closing Stock=calculate ( [Movement],
filter
(all ('Table'[Date] ),
'Table'[Date]<=max('Table'[Date] )))
There is a problem in the results of measure No. 2 and 3.
The result is ok if pivot table is viewed for all periods without filtering. But when I filter period (Date, Month or Year) in pivot table, then result is not correct. It does not bring forward the closing stock of previous period.
Please suggest me some change in dax formula or some new formula for opening and closing stock calculation including previous period's data.
I will be very gratefull for any help.
The Pivot table I created is as given below.
Solved! Go to Solution.
Hi
I modify two measures above with these:
Opening Stock = CALCULATE ( [Movement], FILTER ( ALLEXCEPT ( Table1, Table1[Iteam Name] ), 'Table1'[Date] < MAX ( 'Table1'[Date] ) ) )
Closing Stock = CALCULATE ( [Movement], FILTER ( ALLEXCEPT ( Table1, Table1[Iteam Name] ), 'Table1'[Date] <= MAX ( 'Table1'[Date] ) ) )
Finally, I get this result.
Best Regards
Maggie
Hi
I modify two measures above with these:
Opening Stock = CALCULATE ( [Movement], FILTER ( ALLEXCEPT ( Table1, Table1[Iteam Name] ), 'Table1'[Date] < MAX ( 'Table1'[Date] ) ) )
Closing Stock = CALCULATE ( [Movement], FILTER ( ALLEXCEPT ( Table1, Table1[Iteam Name] ), 'Table1'[Date] <= MAX ( 'Table1'[Date] ) ) )
Finally, I get this result.
Best Regards
Maggie
Is it possible to incorporate a max inventory allowed? For example, the max inventory is 25 and minimum inventory is 5. The opening inventory on 8/31 and 10/15 would have the 5 (minimum allowed) and the inventory on 6/1 would be 25 instead of 30, since 25 is the max. I would then add a column that would reflect the overage (such as "-2" for the days when there were only 3 and "5" for the day inventory exceeded 25).
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
85 | |
67 | |
59 |
User | Count |
---|---|
150 | |
120 | |
99 | |
87 | |
68 |