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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
etalon
Frequent Visitor

Binning (sort of) time stamped values and summing

I have tried a few methods, and although I may have worked out a really convoluted way I could theoretically do this, it seems like it was not the way things are supposed to be done in Power BI (and would make visualisation really difficult).

 

The data is a list of tanks, "TankDB" (which includes various bits of tank related data), along with obviously the list of unique tank IDs.

 

TankDB:

TankID
0670-1
0694-1
0800-1
0804-1
ect…

 

A fuel level table, which has time/date stamped fuel levels, and the tank ID it was recorded against:

 

FuelLevels:

DateTimeLevelTankID
10/04/2019 09:4912890670-1
07/05/2019 14:4313500670-1
14/06/2019 09:5714000670-1
01/07/2019 11:3914000670-1
11/07/2019 08:5714000670-1
16/07/2019 10:2613100670-1
24/07/2019 10:5914250670-1
07/05/2019 10:1522000800-1
19/06/2019 08:0219000800-1
26/06/2019 08:3020200800-1
02/07/2019 09:5620000800-1
10/07/2019 11:1420000800-1
15/07/2019 07:0720000800-1
18/07/2019 06:4820000800-1
22/07/2019 07:3719500800-1
26/07/2019 07:1819000800-1
ect..ect..ect..

 

The particular output I am after is a table as follows:

SumLevels:

WeekDateSum Levels
106/01/2019?
213/01/2019?
320/01/2019?
427/01/2019?
503/02/2019?
610/02/2019?
717/02/2019?
824/02/2019?

 

The way I want the Sum Levels column to work: For each Tank ID in TankDB, find the latest fuel level record that does not exceed the date in Date column. Then, sum all of these found values together.  This will then result in a value which is the total quantity of fuel in the tanks up to a given date.

 

I can generate the table of dates OK I think, but I am stuck after this.

 

My non very non dax pseduocode which might explain my intentions:

 

foreach (tankID in tankDB){

   output=filter(FuelLevels, FuelLevels[DateTime]<SumLevels[Date],FuelLevels[TankID]=tankID)

  latestMatchingLevel=Mostrecent(output, [Level]

  sumFuel+=LatestMatchingOuput

}

 

Thankyou so much for any help!

1 ACCEPTED SOLUTION
etalon
Frequent Visitor

OK, I gave up using Power BI to do this. I have done the data processing in C# to get the data how I want it.

View solution in original post

4 REPLIES 4
v-xuding-msft
Community Support
Community Support

Hi @etalon ,

I created a measure to implement you can have a try.

 

Measure = CALCULATE(SUM(Table4[Level]),FILTER(Table4,Table4[DateTime] <= MAX(Table6[Date]) && Table4[DateTime] >= MAX(Table6[Date])-7 ))

1.PNG2.PNG

The following is my sample you can download.

sample

 

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sorry, this doesnt quite work as I am after.

 

What I am after (quoting my original post):

For each Tank ID in TankDB, find the latest fuel level record that does not exceed the date in Date column. Then, sum all of these found values together.  This will then result in a value which is the total quantity of fuel in the tanks up to a given date.

 

The measure you have suggested sums all the fuel level data in a particular week, and seems to also double count fuel levels (ie if there is two readings for tank XXX, it will add them both together).

 

What I want is a way to get all the most recent levels for each tank up to a particular cutoff date.

etalon
Frequent Visitor

OK, I gave up using Power BI to do this. I have done the data processing in C# to get the data how I want it.

Thankyou so much for this, 

 

I cant get the download to work for some reason (comming up with as a sharepoint error) will try it by ysing your measure and will let you know!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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