cancel
Showing results for
Search instead for
Did you mean:
Regular Visitor

## Calculate monthly consumption from daily meter reads

Hi,

Here is the data at hand. The data is essentially meter reads for a given meter (MTU is unique) over a period 3 years or so. I want the minimum meter read for a given month and the maximum meter read for a given month for a given MTU and then obtain the difference between the two. That will give me consumption for that month. So in the data below, min is 3/12 : 23618, max is 24,516 on 3/15. So consumption will be 24,516-23,618. Thanks in advance.

There are about 70 meters in total with similar data. There are two daily reads per meter.

 MTU Timestamp Read 41149978 03/12/2014 07:24:34 23618 41149978 03/12/2014 19:31:39 23777 41149978 03/13/2014 07:37:08 23925 41149978 03/13/2014 19:42:48 24103 41149978 03/14/2014 07:50:02 24256 41149978 03/14/2014 19:56:47 24397 41149978 03/15/2014 08:01:08 24516

1 ACCEPTED SOLUTION
Community Champion

In Power Query you can select column Timestamp and:

Add Column - Date - Year

Add Column - Date - Month

Then on the Transform tab - Select columns MTU, Year, Month and choose Group By

Add Operations Max and Min

On Add Column tab: select Max and Min columns and choose Standard - Subtract

Rename the new column "Consumpton"

Generated code:

```let
Source = #"Daily Meter Reads",
#"Inserted Year" = Table.AddColumn(Source, "Year", each Date.Year([Timestamp]), type number),
#"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([Timestamp]), type number),
#"Grouped Rows" = Table.Group(#"Inserted Month", {"MTU", "Year", "Month"}, {{"Max", each List.Max([Read]), type number}, {"Min", each List.Min([Read]), type number}}),
#"Inserted Subtraction" = Table.AddColumn(#"Grouped Rows", "Inserted Subtraction", each [Max] - [Min], type number),
#"Renamed Columns1" = Table.RenameColumns(#"Inserted Subtraction",{{"Inserted Subtraction", "Consumption"}})
in
#"Renamed Columns1"```

Result:

Specializing in Power Query Formula Language (M)
6 REPLIES 6
New Member

Hello Guys,

The Energy Consumption Calculation is great by using Daily Substraction Max and Min from meter reading but I faced a problem which is the meter reading reached 999999 units will roll over or start over from 0 unit. Example in one day 0700pm the meter reading is 999838.58 units, 11pm the meter reading 551.86 units, therfore the Max and Min will calculate wrong Energy Consumption on that day. May I know how to handle this kind of data which the device will roll over? Sample Data Sheet as shown below

 Thu, 10 May 2018 07:00:00 PM 999839 Thu, 10 May 2018 07:30:00 PM 999921 Thu, 10 May 2018 08:00:00 PM 1.6 Thu, 10 May 2018 08:30:00 PM 82.14 Thu, 10 May 2018 09:00:00 PM 160.59 Thu, 10 May 2018 09:30:00 PM 236.17 Thu, 10 May 2018 10:00:00 PM 311.09 Thu, 10 May 2018 10:30:00 PM 388.34 Thu, 10 May 2018 11:00:00 PM 471.2 Thu, 10 May 2018 11:30:00 PM 551.86
Anonymous
Not applicable

I have a setup of data for which I need to calculate the following:

- Yearly Usage of a product

- Average Monthly usage of a product

- Months of stock on hand

- Minimum Lead time

- Average Lead time

- Maximum Lead time

- Reorder Point

- Minimum on hand

- Safety Stock

I'm not too versed in DAX code and expressions. If anyone can suggest how I need to set up my data to calculate these and the code to which I need to enter to calculate these would be great.

Thank you!

Microsoft

Hi @abhijeetbarve,

Have you resolved your problem? If you have, please mark the right replay as answer, so other people will benefit from it. If it hasn't, please feel free to ask any issue.

Best Regards,
Angelia

Super User

hi  there,

not sure you have a calendar table in your dataset or not, if not then you should add one. although i create  a table from your table and dropped it in a table visual to get the exepcted resulted, added on measure to get the difference between min and max.

Table

Output

DAX Calculation for Reading Measure

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Regular Visitor

Thanks for the reply.

Community Champion

In Power Query you can select column Timestamp and:

Add Column - Date - Year

Add Column - Date - Month

Then on the Transform tab - Select columns MTU, Year, Month and choose Group By

Add Operations Max and Min

On Add Column tab: select Max and Min columns and choose Standard - Subtract

Rename the new column "Consumpton"

Generated code:

```let
Source = #"Daily Meter Reads",
#"Inserted Year" = Table.AddColumn(Source, "Year", each Date.Year([Timestamp]), type number),
#"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([Timestamp]), type number),
#"Grouped Rows" = Table.Group(#"Inserted Month", {"MTU", "Year", "Month"}, {{"Max", each List.Max([Read]), type number}, {"Min", each List.Min([Read]), type number}}),
#"Inserted Subtraction" = Table.AddColumn(#"Grouped Rows", "Inserted Subtraction", each [Max] - [Min], type number),
#"Renamed Columns1" = Table.RenameColumns(#"Inserted Subtraction",{{"Inserted Subtraction", "Consumption"}})
in
#"Renamed Columns1"```

Result:

Specializing in Power Query Formula Language (M)

## Helpful resources

Announcements

#### Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

#### Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors
Top Kudoed Authors