Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
I hope someone can help me, In my data table I have the following
Account, Contract Start Date, Contract end date, amount , number of days in contract, rev per day.
xxx, 1st march 2019, 31st May 2019, 1000, 92, £9.57
Basically we received for example £1000 but i want to allocate the revenue across the 3 months based upon the number of days in each month. For example
March - 31 days = £336.96
April - 30 days = £326.09
May - 31 days = £336.96
Total £1000
I have a data table and a calender table. so I think it would be a crossjoin, but just cant quite get it right. ANy help would be appreciated
Cheers
Solved! Go to Solution.
personally i would do this in the query editor
i have attached a link to an example. go into the query editor and click on the table. on the right hand side you will see the steps i took to calculate your desired result as below
baics is to calculate your days per total, then calcualte the amount per month, finally create a custom colunm that contains an array of all dates between to the start and end date. and then finally expand this colunm
Proud to be a Super User!
personally i would do this in the query editor
i have attached a link to an example. go into the query editor and click on the table. on the right hand side you will see the steps i took to calculate your desired result as below
baics is to calculate your days per total, then calcualte the amount per month, finally create a custom colunm that contains an array of all dates between to the start and end date. and then finally expand this colunm
Proud to be a Super User!
thanks Anthony, you are a star this worked perfectly. Thank you for your help it is very much appriciated
Hi @tmears
Please see the attached Query Editor version.
Is there a performance concern with doing it in DAX and that is why you use PQ?
Hi @jdbuchanan71,
Most of the time I would do things like expanding dates in Query Editor ( most probably even write a SQL script if applicable, as I could not find functions that achieve this and supports Query Folding at the same time ), mainly for the reasons that @AnthonyTilley mentioned, however, performance would be one factor as well specially with larger datasets like Employee Start / End dates where you have individuals working for many years.
Having said that I think your DAX solution works very well and its a question of preference and having a choice of solutions.
From My point of view its just easier.
I awlays prefer to have the data loaded at the lowest granularity you wish to work at. this way if later in the project you are asked to make an alternative view of the data it is being loaded at the required level already.
because your wanting to calculate at a day level it is best to load all the data at a day level.
Proud to be a Super User!
Hello @tmears
The following measure should get you what you are looking for. In my example the Dates table and the Contracts table are not joined, I just use them as filtering although I do use the Month Year column from the Dates table for the visual.
Please note that I do not use the [days in contract] or [rev per day] from the table, I calculate them in the measure. It is safer that way, fewer things to possibly be out of alignment.
Contract Value = SUMX ( Contracts, VAR MinDate = FIRSTDATE ( Dates[Date] ) VAR MaxDate = LASTDATE ( Dates[Date] ) VAR ContStart = Contracts[Contract Start] VAR ContEnd = Contracts[Contract End] VAR FromDate = MAX ( MinDate, ContStart ) VAR ToDate = MIN ( MaxDate, ContEnd ) VAR DaysInContract = DATEDIFF ( Contracts[Contract Start], Contracts[Contract End], DAY ) +1 VAR DailyValue = DIVIDE ( Contracts[amount], DaysInContract) RETURN IF ( LASTDATE ( Dates[Date] ) < ContStart || FIRSTDATE ( Dates[Date] ) > ContEnd, BLANK (), ( DATEDIFF ( FromDate, ToDate, DAY ) + 1 ) * DailyValue ) )
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.