Forum Discussion
Getting the correct SUM for Inventory Levels based on DIM_KEY
Hi All,
Firslty lbendlin thank you for your solution!
And rcb0325 ,According to your description, you want to realize three requirements, respectively, the day of the day, the current month, the previous year's Qty of the month to get the sum of the right?
TotalQuantityYTD =
CALCULATE(
SUM('Table2'[QTY]),
FILTER('Table2',
'Table2'[DATE] >= DATE(YEAR(TODAY()), 1, 1) && 'Table2'[DATE] <= TODAY()
)
)TotalQuantityMonthToDate =
VAR EndMonth = EOMONTH(TODAY(), 0)
VAR Result =
CALCULATE(
SUM('Table2'[QTY]),
FILTER('Table2',
'Table2'[DATE] >= DATE(YEAR(TODAY()), 1, 1) && 'Table2'[DATE] <= EndMonth
)
)
RETURN
ResultTotalQuantityWithYearOffset =
VAR YearOffset = SELECTEDVALUE('YearOffsetTable'[Value], 0)
VAR Result =
CALCULATE(
SUM('Table2'[QTY]),
FILTER('Table2',
'Table2'[DATE] >= DATE(YEAR(TODAY()) + YearOffset, 1, 1) && 'Table2'[DATE] <= TODAY()
)
)
RETURN
Result
The above requirements represent your corresponding three needs, if you want to switch the date freely, you can use selectvalue to replace the today function.
If you have further questions, you can check the pbix file I uploaded, I hope to help you, if I can help you solve the problem I will be touched with great honor!
Hope it helps!
Best regards,
Community Support Team_ Tom Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for your response.
I have tried the calculations you provided, and they do not seem to sum the inventory levels correctly.
I have included two tables below that show the output values, and what the correct values should be.
To provide more clarification, the fact InventoryValue table has a "many to one" relationship to the dim TransactionDate table.
Here are the formulas you provided, but with the correct table names. I do not have a "Year Offset" table, so am unable to include the third formula.
| Year | Max of DateDIM_KEY | QTY | InventoryLevel YTD | Correct YTD |
| 2024 | 4749 | (577,785.50) | (577,785.50) | 1,766,341.29 |
| 2023 | 4383 | (621,314.21) | 2,344,126.79 | |
| 2022 | 4018 | 2,965,441.00 | 2,965,441.00 |
| YYYY-MM | Max of DateDIM_KEY | QTY | InventoryLevel MTD | Correct MTD |
| 2024-11 | 4718 | 26,631.50 | 26,631.50 | 1,766,341.29 |
| 2024-10 | 4688 | (83,228.00) | (83,228.00) | 1,739,709.79 |
| 2024-09 | 4657 | (137,987.50) | (137,987.50) | 1,822,937.79 |
| 2024-08 | 4627 | 65,781.50 | 65,781.50 | 1,960,925.29 |
| 2024-07 | 4596 | 135,291.00 | 135,291.00 | 1,895,143.79 |
| 2024-06 | 4565 | 38,303.00 | 38,303.00 | 1,759,852.79 |
| 2024-05 | 4535 | (26,480.00) | (26,480.00) | 1,721,549.79 |
| 2024-04 | 4504 | (12,062.00) | (12,062.00) | 1,748,029.79 |
| 2024-03 | 4474 | (22,471.00) | (22,471.00) | 1,760,091.79 |
| 2024-02 | 4443 | (22,537.00) | (22,537.00) | 1,782,562.79 |
| 2024-01 | 4414 | (539,027.00) | (539,027.00) | 1,805,099.79 |
| 2023-12 | 4383 | (40,870.00) | 2,344,126.79 | |
| 2023-11 | 4352 | 7,149.00 | 2,384,996.79 | |
| 2023-10 | 4322 | (288,001.50) | 2,377,847.79 | |
| 2023-09 | 4291 | 31,523.00 | 2,665,849.29 | |
| 2023-08 | 4261 | (197,243.40) | 2,634,326.29 | |
| 2023-07 | 4230 | (122,638.00) | 2,831,569.69 | |
| 2023-06 | 4199 | (117,131.10) | 2,954,207.69 | |
| 2023-05 | 4169 | (21,942.00) | 3,071,338.79 | |
| 2023-04 | 4138 | 121,751.84 | 3,093,280.79 | |
| 2023-03 | 4108 | (261,740.00) | 2,971,528.95 | |
| 2023-02 | 4077 | 317,751.00 | 3,233,268.95 | |
| 2023-01 | 4049 | (49,923.05) | 2,915,517.95 | |
| 2022-12 | 4018 | 2,965,441.00 | 2,965,441.00 |
- Anonymous1 year agoNot applicable
Hi rcb0325 ,
According to your needs you want to realize the date from the smallest to the largest for a cumulative, right?
We've made some changes to the code to accomplish your needs.InventoryLevel YTD = VAR _YTD =(CALCULATE( SUM('fact InventoryValueView'[ QTY ]),FILTER(ALL('dim Transaction Date'), 'dim Transaction Date'[Year] <=MAX('dim Transaction Date'[Year]) ) )) RETURN _YTDInventoryLevel MTD = VAR _MTD = (CALCULATE( SUM('fact InventoryValueView'[ QTY ]),FILTER(ALL('dim Transaction Date'), 'dim Transaction Date'[Date]<=MAX('dim Transaction Date'[Date])) )) RETURN _MTDIf you have further questions you can check out my pbix file, I hope it helps and I would be honored if I could solve your problem!
If you still have questions you can check out my pbix file, I hope it helps and I would be honored if I could solve your problem!
Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.