Forum Discussion
Need urgent help - DAX calculation
Hi Kolumam
if you are looking to split the rate proportionally by days then consider the attached solutions using Power Query and DAX table
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
Hi Mariusz
Thanks for trying but your solution is incorrect. See below.
For 2019, you are taking the whole year, rather you should only take the number of days between 1st July 2019 and 31st Dec 2019. So it will be (375*60/180)+(405*120/180) which is 395. As you can see for contract X, we have two contracts on the same year. If that happens, then you need to divide by the number of days from the start date of contract to end of the year of start date of contract. If there are no two contracts in a year, say for example, the start date is 1st April 2017 for contract Y, in that case for 2017, it should take the entire year. So it will be (380*365*365) which is 380 instead of 286.83. From 2018, the value is prorated accordingly.
Do you get it?
- Kolumam6 years ago
Post Prodigy
Hi people,
My question is still not solved yet. Can anyone please help?
@parry2k @mahoney19 @Amit @parry2k @az38 @jdbuchanan71 @mahoneypat @edhans @harshnathani @v-kellya-msft @MFelix @Ashish_Mathur @BA_Pete @ryan_mayu @kbuckvol @Alexander76877 @Petazo @Mariusz @TomMartens @Greg_Deckler @tjd @Sean @mikstra @AllisonKennedy @EricHulshof @briandpeterson @USG_Phil @vpatel55 @mwegener @v-piga-msft @tex628 @sturlaws @Vvelarde @CheenuSing @MarcelBeug @Zubair_Muhammad @v-piga-msft @danextian @MattAL @MattAllington @roalexan @Alexander76877 @kgc
- ImkeF6 years ago
Community Champion
Hi Kolumam ,
as the others have mentioned already, the problem with the sample you've provided is that there are inconsistencies/errors in it that make determine the desired logic hard.
The following code calculates proportional values according to the actual number of days in the year:
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "dc1LCsAwCATQu7gOqPkQc5OW4P2vUQ2RhkJ3M/IY5wTGjpl4QILCKJEv772BJifjIMVypk0qbZKxxd2MVSscOxI71Xf6u8Ni+V6ETiKfV04qb8I/r9YOFVB9AA==", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table[ #"Start Date of Contract" = _t, #"End Date of Contract" = _t, #"Operation Name" = _t, #"Comprehensive O&M Price" = _t ] ), #"Changed Type" = Table.TransformColumnTypes( Source, { {"Start Date of Contract", type date}, {"End Date of Contract", type date}, {"Operation Name", type text}, {"Comprehensive O&M Price", Int64.Type} } ), AddListOfYears = Table.AddColumn( #"Changed Type", "Year", each {Date.Year([Start Date of Contract])..Date.Year([End Date of Contract])} ), #"Expanded ListOfYears" = Table.ExpandListColumn(AddListOfYears, "Year"), AddStart = Table.AddColumn( #"Expanded ListOfYears", "Start", each List.Max({[Start Date of Contract], #date([Year], 1, 1)}) ), AddEnd = Table.AddColumn( AddStart, "End", each List.Min({[End Date of Contract], #date([Year], 12, 31)}) ), AddDuration = Table.AddColumn( AddEnd, "DurationInDays", each Duration.Days([End] - [Start]) + 1, Int64.Type ), AddDaysInYear = Table.AddColumn( AddDuration, "DaysInYear", each if Date.IsLeapYear(#date([Year], 1, 1)) then 366 else 365 ), AddAnnualShare = Table.AddColumn( AddDaysInYear, "AnnualShare", each [DurationInDays] / [DaysInYear] ), WeightPriceByShare = Table.AddColumn( AddAnnualShare, "AnnualContractValue", each [#"Comprehensive O&M Price"] * [AnnualShare], type number ) in WeightPriceByShareIt creates a table in the query editor that will hopefully allow you to follow the logic and see where your numbers are wrong:
In general your numbers are too low because your using 365 days a year and weight your months only with 30 days (adding up to 360).
A specific inconsistency in your calculation is that you allocate partial end years pro rata (i.e. Y 410 for 2020: 90 days (Jan-Mar)) but all partial start years with full year (Y 380 with 365 days, although the contract starts in April and X 395 divided by only 180 (instead of 360)).
So my calculation assumes that the "Comprehensive O&M Price" is an annual fee that has to be allocated to partial years consistently.