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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HopkiJ
Frequent Visitor

Calculate Monthly Usage using multiple filters in Power Query

Hi Everyone,

I have built a system to manage my energy in Power Bi but I'm unable to figure out how to manage the manual meter readings within it. 

I receive monthly reads on different days across multiple sites and meters (but only one read each meter per month) I need to calculate the consumption per month per meter per site. An example is below. I've tried grouping and Max-Min, merging with the date table and filling down and non of these solutions is working. 

Any help would be greatly appreciated! 

 

Site NameMeter RefDateReading
Site 1Meter 1125/05/2021112
Site 2Meter 227/05/202186504
Site 1Meter 1225/05/2021889932
Site 3Meter 322/05/202177846
Site 1Meter 1125/06/20211230
Site 2Meter 227/06/202186558
Site 1Meter 1225/06/2021889944
Site 3Meter 322/06/202185846
    
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @HopkiJ ,

 

Please follow the steps below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY4xCoAwEAS/IqkFk03ucnmElaVYprAV/49ENDlE0u3CMMy6mmU/8+DMaOZ85mNwZYImSxMsynEOZhsfEBUsC1FxwmRDI5USX6VISl5ZfWXLAhQaowT+tb6hXEPhba+UVSlJt5R1aQi90obSXbpd", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Site Name" = _t, #"Meter Ref" = _t, Date = _t, Reading = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Site Name", type text}, {"Meter Ref", type text}, {"Date", type text}, {"Reading", Int64.Type}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Date", type date}}, "fr-DZ"),
    #"Sorted Rows" = Table.Sort(#"Changed Type with Locale",{{"Site Name", Order.Ascending}, {"Meter Ref", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Site Name", "Meter Ref"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1)}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows",{"Data",(x)=>Table.AddColumn(x,"Monthly Usage",each try (x[Reading]{[Index]}-x[Reading]{[Index]-1}) otherwise null )}),
    #"Expanded Data" = Table.ExpandTableColumn(Custom1, "Data", {"Date", "Monthly Usage"}, {"Date", "Monthly Usage"})
in
    #"Expanded Data"

vcgaomsft_0-1674456325437.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

Thank you Gao, the help is greatly appreciated.

I followed the above and it all looks correct except my "Monthly Usage" values have come out at null

Can you tell where I have gone wrong? 

 

= Table.TransformColumnTypes(#"Changed Type2", {{"Date", type date}}, "en-GB")
 

= Table.Sort(#"Changed Type with Locale",{{"Site Name", Order.Ascending}, {"Meter Ref", Order.Ascending}, {"Date", Order.Ascending}})

 

= Table.Group(#"Sorted Rows", {"Site Name", "Meter Ref"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1)}})
 

= Table.TransformColumns(#"Grouped Rows",{"Data",(x)=>Table.AddColumn(x,"Monthly Usage",each try (x[Reading]{[Index]}-x[Reading]{[Index]-1}) otherwise null )})
 

= Table.ExpandTableColumn(Custom1, "Data", {"Date", "Monthly Usage"}, {"Date", "Monthly Usage"})

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @HopkiJ ,

 

Please follow the steps below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY4xCoAwEAS/IqkFk03ucnmElaVYprAV/49ENDlE0u3CMMy6mmU/8+DMaOZ85mNwZYImSxMsynEOZhsfEBUsC1FxwmRDI5USX6VISl5ZfWXLAhQaowT+tb6hXEPhba+UVSlJt5R1aQi90obSXbpd", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Site Name" = _t, #"Meter Ref" = _t, Date = _t, Reading = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Site Name", type text}, {"Meter Ref", type text}, {"Date", type text}, {"Reading", Int64.Type}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Date", type date}}, "fr-DZ"),
    #"Sorted Rows" = Table.Sort(#"Changed Type with Locale",{{"Site Name", Order.Ascending}, {"Meter Ref", Order.Ascending}, {"Date", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Site Name", "Meter Ref"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1)}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows",{"Data",(x)=>Table.AddColumn(x,"Monthly Usage",each try (x[Reading]{[Index]}-x[Reading]{[Index]-1}) otherwise null )}),
    #"Expanded Data" = Table.ExpandTableColumn(Custom1, "Data", {"Date", "Monthly Usage"}, {"Date", "Monthly Usage"})
in
    #"Expanded Data"

vcgaomsft_0-1674456325437.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thank you Gao, the help is greatly appreciated.

I followed the above and it all looks correct except my "Monthly Usage" values have come out at null

Can you tell where I have gone wrong? 

 

= Table.TransformColumnTypes(#"Changed Type2", {{"Date", type date}}, "en-GB")
 

= Table.Sort(#"Changed Type with Locale",{{"Site Name", Order.Ascending}, {"Meter Ref", Order.Ascending}, {"Date", Order.Ascending}})

 

= Table.Group(#"Sorted Rows", {"Site Name", "Meter Ref"}, {{"Data", each Table.AddIndexColumn(_,"Index",1,1)}})
 

= Table.TransformColumns(#"Grouped Rows",{"Data",(x)=>Table.AddColumn(x,"Monthly Usage",each try (x[Reading]{[Index]}-x[Reading]{[Index]-1}) otherwise null )})
 

= Table.ExpandTableColumn(Custom1, "Data", {"Date", "Monthly Usage"}, {"Date", "Monthly Usage"})

KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @HopkiJ ,

This can be easily achieved through DAX.

Monthly Consumption =
VAR prevMth =
CALCULATE(
    SUM('Table'[Reading]),
    PARALLELPERIOD(
        'Table'[Date].[Date],
        -1,
        MONTH)
)
VAR currMth = SUM('Table'[Reading])
RETURN
currMth - prevMth
Regards
KT

Regrettably this just aggregated the consumption but thank you!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.