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, I wonder if someone could help me. I have a table with people details and associated costs, these costs can span many years and I need to get the total cost in each fiancial year which is April to March, that the cost was open for.
Cost Start | Cost End | Days Open 2022-2023 | Days Open 2023-2024 | Days Open 2024-2025 |
01/01/2022 | 365 | 365 | 365 | |
01/04/2023 | 30/06/2024 | 0 | 366 | 91 |
I have created a formula that gets the total cost for each person based on the days that it was open, but when I add this into my visual it's only calculating those costs that opened in that year and does not calculate for each of the years that it was open.
Hi @SuzieKidd ,
Please try this:
Total Costs All =
VAR __maxDate = MAX(Calendar_Lookup[Date])
VAR __minDate = MIN(Calendar_Lookup[Date])
RETURN
CALCULATE(SUM(CPLIFactor[Total Cost]), FILTER( ALLSELECTED(CPLIFactor),CPLIFactor[Start Date] <= __maxDate && (__minDate < CPLIFactor[End Date] || ISBLANK(CPLIFactor[End Date]))))
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @SuzieKidd - calculate the total cost for each financial year (April to March) that the cost was open,create a financial year column in your Calendar_Lookup table to differentiate between the financial years.
Financial Year =
IF(
MONTH(Calendar_Lookup[Date]) >= 4,
YEAR(Calendar_Lookup[Date]),
YEAR(Calendar_Lookup[Date]) - 1
)
create measure to calculate the total cost per financial year considering the days:
Days Open in FY =
VAR __fyStart = DATE(YEAR(Calendar_Lookup[Date]), 4, 1)
VAR __fyEnd = DATE(YEAR(Calendar_Lookup[Date]) + 1, 3, 31)
RETURN
CALCULATE(
SUMX(
CPLIFactor,
DATEDIFF(
MAX(__fyStart, CPLIFactor[Start Date]),
MIN(__fyEnd, COALESCE(CPLIFactor[End Date], __fyEnd)),
DAY
)
),
FILTER(
CPLIFactor,
CPLIFactor[Start Date] <= __fyEnd &&
(ISBLANK(CPLIFactor[End Date]) || CPLIFactor[End Date] >= __fyStart)
)
)
Create another measure for Proportional Cost:
Total Costs per FY =
VAR __fyStart = DATE(YEAR(Calendar_Lookup[Date]), 4, 1)
VAR __fyEnd = DATE(YEAR(Calendar_Lookup[Date]) + 1, 3, 31)
RETURN
CALCULATE(
SUMX(
CPLIFactor,
(CPLIFactor[Total Cost] / DATEDIFF(CPLIFactor[Start Date], COALESCE(CPLIFactor[End Date], TODAY()), DAY)) *
DATEDIFF(
MAX(__fyStart, CPLIFactor[Start Date]),
MIN(__fyEnd, COALESCE(CPLIFactor[End Date], __fyEnd)),
DAY
)
),
FILTER(
CPLIFactor,
CPLIFactor[Start Date] <= __fyEnd &&
(ISBLANK(CPLIFactor[End Date]) || CPLIFactor[End Date] >= __fyStart)
)
)
Try the above approach and let know , hope you already have a seperate date table.
By calculting the above measure we will get the total cost per financial year based on the number of days the cost was open within that financial year
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Proud to be a Super User! | |
Hi Rajendraongole, thank you so much for this, the financial year one worked really well, I already have a query to calculate the days as we have some weird ways of recording for example costs can open and close on the same day as a one off cost but is an actual weekly cost so I assign the days as 7. The calculation query I'm getting the following when I tyr and create the measure.
"A single value for column 'Date' in table 'Calendar_Lookup' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result." Sorry if I'm being a bit dense, I'm still on a very steep learning curve.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
146 | |
97 | |
79 | |
69 |