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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
skumar0105
Helper II
Helper II

How to calculate Energy consumption (in kWh) of a machine on daily basis for a specific time.

Hi Team,

i want to calculate Energy consumption of a machine from a Totaliser column named as 'Machine X Active Energy (units)', this is a time series data and the Energy units are taken from Energy meters.

i need to calculate the consumption in kWh from previous day 07:00 AM to current day 07:00 AM.

My data looks like this:

DateTimeMachine 1 Active Energy (units)Machine 2 Active Energy (units)Machine 3 Active Energy (units)
26.07.202206:57:317269272674.66867612845471589.39355318123974201.95564
26.07.202200:22:317267540644.58384312845379641.5887818123786079.53212
26.07.202218:27:317266245906.0395812845061335.79620718123426670.89311
26.07.202211:17:317266245906.0395812844777211.47661218123273023.622402
26.07.202207:02:317265416899.9397912844460165.4259818123089148.049168
25.07.202207:07:317265357109.05880412844289521.82711618122760262.45503
25.07.202223:32:317265276500.57887112843961707.8690618122325606.47833
25.07.202212:17:317265145305.04586212843756481.26164418122081476.525288
25.07.202207:02:317265026727.55421112843555771.599396 18121898035.09134

 

 

The calculated column will look like this:

DateMachine 1 Energy in kWhMachine 2 Energy in kWhMachine 3 Energy in kWh
26.07.20221568.00923.002340.00
25.07.20221289.00845.002245.00

i am new to Power BI, kindly help with query.

 

 

Regards

Satish

5 REPLIES 5
ronrsnfld
Super User
Super User

Could you please show the actual numbers you are using from your data table to come up with the expected results for Machine 1.  If I use the values closest to 7AM, I get very different results from what you show.

Hi @ronrsnfld 

Please ignore the numbers mentioned in output table, this was shown for example only. actual results may vary.

please refer below screen shot:

skumar0105_0-1659148283833.png

 

Here is a solution based on your textual example data.

I tried to write it so you could add any number of machine columns. But if your real data is much different from what you presented as text data, you may need to adapt the code to your actual situation.

let
    Source = Excel.CurrentWorkbook(){[Name="Table12"]}[Content],

//Need this list so query can be dynamic with any number of machines
//  Seems like the ending "Active Energy (units)" is the key
    Machines = List.Select(Table.ColumnNames(Source), each Text.Contains(_,"Active Energy (units)")),
    #"Changed Type" = Table.TransformColumnTypes(Source, {{"Date", type date}, {"Time", type time}} & 
        List.Transform(Machines, each {_, type number}) ,"en-150"),

//Seconds to 7 AM (for calculating "closest")
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Seconds to 7AM", 
        each Number.Abs(Duration.TotalSeconds(([Date] & #time(7,0,0)) - ([Date] & [Time])))),
    
//Group by date and extract row with closest to 7AM time
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Date"}, {
        {"7 AM", (t)=> Table.SelectRows(t, each List.Min(t[Seconds to 7AM]) = [Seconds to 7AM])}
        }),
    #"Expanded 7 AM" = Table.ExpandTableColumn(#"Grouped Rows", "7 AM", {"Time"} & Machines),

//reset the data types
    reType = Table.TransformColumnTypes(#"Expanded 7 AM", {{"Time", type time}} & List.Transform(Machines, each {_, type number})),

//unpivot the "machine" columns
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(reType, {"Date", "Time"}, "Attribute", "Value"),

//Group by attribute (machine name)
//  Then calculated monthly change = kWh consumed for the month
    #"Grouped Rows1" = Table.Group(#"Unpivoted Other Columns", {"Attribute"}, {
        {"Monthly kwH", (t)=>
            Table.AddColumn(
                Table.FromColumns(
                    Table.ToColumns(t) & 
                    {{null} & List.RemoveLastN(t[Value],1)},
                    type table[Date=date, Time=time, Attribute=text, Value=number, shifted=number]), 
            "Month kwH", each ([shifted] - [Value]) / 1000, type number)}
        }),

//expand the grouped tables
    #"Expanded Monthly kwH" = Table.ExpandTableColumn(#"Grouped Rows1", "Monthly kwH", {"Date", "Time", "Month kwH"}),

//Change Machine name to become the new column headers after pivoting
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Monthly kwH","Active Energy (units)","Energy in kWh",Replacer.ReplaceText,{"Attribute"}),

//Pivot on the Attribute column with no aggregation
    #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Attribute]), "Attribute", "Month kwH"),

// reset the data types, then by date descending
    #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",
        {{"Date", type date}, {"Time", type time}} & 
            List.Transform(List.RemoveFirstN(Table.ColumnNames(#"Pivoted Column"),2), each {_, type number})),
    #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Date", Order.Descending}})
in
    #"Sorted Rows"

Source Data

ronrsnfld_0-1659200997954.png

Results

ronrsnfld_1-1659201055971.png

 

 

 

 

v-jingzhang
Community Support
Community Support

Hi @skumar0105 

 

What is the current unit of values in 'Machine X Active Energy (units)' columns? Can you please take Machine 1 Energy as an example to help elaborate how to calculate using the current data to get the result 1568.00 and 1289.00 for the listed two dates? Currently I don't understand how to get these results. 

 

Best Regards,
Community Support Team _ Jing

Hi @v-jingzhang 

Currently the 'Machine X Active Energy (units)'  are recorded in kw only.

the data provided in table above is just for the explanation, the source is pushing the data at every 5 mins interval in a sql database. i.e. there are 12 rows per hour and 288 rows per day are recorded.

now i want to calculate each machine's daily Active Energy Units in kWh for a give period of 24 hours.

i.e. Active energy units (kw) = date.today(29.07.2022), time 07:00:00 - date.yesterday(28.07.2022), time 07:00:00.

kWh =  Active energy units (kw)/1000   ------------>(since 1 kWh = kwxno. of hours./1000)

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors