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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.