March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello all!
I am trying to calculate the correct inventory level, shown by month.
The [QTY] column is a "hard coded" column of the inventory transactions out of D365. This inventory value is only correct if ALL of the dates are summed.
The date DIM_KEY is a chronological number.
The first table shows the DIM_KEY with date and transactions. The other two tables have it shown by YYYY-MM and YYYY.
What I am trying to do is sum based on month/year (selected month/year to show <= DAY(Today() or same period)
For example,
The Inventory Level for the each date would need to calculate all DIM_KEYs <= Selected date
The Inventory Level for 2024-10 would need calculate all DIM_KEYs <= 10/27/2024 (assuming the current date is 11/27/2024).
The Inventory Level for the year of 2023 would need to calculate the all DIM_KEYs <= 10/27/2023.
I hope this makes sense, and someone can help! I can provide any info needed. Thanks!
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
Result
TotalQuantityWithYearOffset =
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 |
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
_YTD
InventoryLevel MTD =
VAR _MTD =
(CALCULATE(
SUM('fact InventoryValueView'[ QTY ]),FILTER(ALL('dim Transaction Date'),
'dim Transaction Date'[Date]<=MAX('dim Transaction Date'[Date]))
))
RETURN
_MTD
If 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 Shen
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
User | Count |
---|---|
120 | |
77 | |
58 | |
52 | |
46 |
User | Count |
---|---|
171 | |
117 | |
63 | |
57 | |
51 |