Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
SantiYegros
Frequent Visitor

Measure, Calculated column or Table to solve this

Hello, I am working with data from cattleraising. I am currently facing a challenge and haven't been able to work around it. I have a two tables, Table 1 with 3 columns, [ID], [Date] and [Kg]. The other table is a Calendar table. On Table 1 there are several Dates for when [ID] have been weighted throughout the year.
I have created a measure called [GDP] to calculate the wieght gained per day between one Date and the next for each [ID]. Now i am trying to to find the average of [GDP] of all [ID] for each day in the Calendar table, regardless of each [ID] having a Date in Table1. 
Example of Table 1

DateIDKg
15/01/202400001150
20/01/202400001155
25/01/202400001165

[GDP] of ID 00001 between dates 1 and 2 is 1 kg/day where GDP is (155-150)/(5) 
[GDP] of ID 00001 between dates 2 and 3 is 2 kg/day where GDP is (165-155)/(5) 
Example of table needed and don't know how to get it:

DateGDP
16/01/20241
17/01/20241
18/01/20241
19/01/20241
20/01/20241
21/01/20242
22/01/20242
23/01/20242
24/01/20242
25/01/20242

If anyone can help, thanks in advanced!

1 ACCEPTED SOLUTION

It's the same formula, minus the offset.

 

lbendlin_0-1716326720791.png

 

View solution in original post

4 REPLIES 4
SantiYegros
Frequent Visitor

You are absolutely right!
Thanks. 
I created a new table instead of using as measure, so I can relate to a calendar table and work with it. Thanks @lbendlin 

lbendlin
Super User
Super User

This is a standard intrapolation.

 

lbendlin_0-1716162478169.png

GPD = 
var d = SELECTEDVALUE('Calendar'[Date])
var pd = maxx(filter('Table',[Date]<d),[Date])
var nd = minx(filter('Table',[Date]>=d),[Date])
var pv = maxx(filter('Table',[Date]=pd),[Kg])
var nv = maxx(filter('Table',[Date]=nd),[Kg])
return if(not ISBLANK(pd) && not ISBLANK(nd),pv + DIVIDE(nv-pv,nd-pd,0)*(d-pd))

Sorry, I didn't explain myself thouroghly. 
I have created a sample dataset to try and explain myself better. This is a visual from my sample table.

SantiYegros_0-1716324017226.png

I need a way to average the GDP for the months (or days) in between the data as well. GDP would be the change of KG between the weighting days. I need to get to this:

SantiYegros_2-1716324875614.png

 

Where the cells in yellow is the GDP but for dates/months where there is no data. In the visual we can see there is no data for december 2023, so the GDP for that ID from January 24 is reflected in dec 23, because that ID had a change of KG of 0,400 per day. So the average per month would indeed reflect the change for every ID for every month.

 

Thanks for the patience and the help!

 

This is the link for my sample data:
SAMPLEPOWERBI

It's the same formula, minus the offset.

 

lbendlin_0-1716326720791.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.