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
KristyP
Helper I
Helper I

Usage forecast DAX

Hi,

 

I am trying to develop a matrix in Power BI to forecast usage based on previous data.

 

We would like the data to be presented as per below:

 

KristyP_0-1702433451179.png

 

Each serial number has it's own line in the matrix.

 

I have two points of usage so was planning to calculate average usage and add this to the current ussage to build the forecast. Can be daily or monthly average. Data looks like the below:

KristyP_1-1702434095685.png

 

Thank you in advance for your assistance.

 

 

3 REPLIES 3
v-weiyan1-msft
Community Support
Community Support

Hi @KristyP , 

 

From your description, please try the following steps:

My Sample:

vweiyan1msft_0-1702897382228.png

1. Please do pivot and other operations in Power query as described in the following advanced code.

vweiyan1msft_2-1702897834040.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hdPNbsMgDAfwV5lyrpBtMB/HNtkb7Fb12OO0aR+HvX1t2i6mLCxCgqDwk/lDjsdp/v78ens9fzztp9308vN+roM9kpcOQR7pCYgcSis6Geg+6R2iw+m023SIWD/lnvEwUg6N4mO7YlX4QQkbjA4OAHhb0jtoIZC2Ac0ymEtRKP6xqzRmZsssXENOphxgp3kVXhUo3a5+laUqrEsw211JErm+wBBamniopsxsIXDpOserk6XGAZM41pQfDHve/xGxaPW5LyTbYLzzOFI45CZLiTc6rQ3tYUNy41RIzzrYS3Njwph5bq4wAOkSGy7ItnQut3fYw8jhfP8VVsdXx1PrEI+ca8TehhMchf6XUuZ0AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Type = _t, #"Serial Number" = _t, #"2022 Usage" = _t, #"2022 Read date" = _t, #"2023 Usage" = _t, #"2023 Read Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Type", type text}, {"Serial Number", type text}, {"2022 Usage", Int64.Type}, {"2022 Read date", type date}, {"2023 Usage", Int64.Type}, {"2023 Read Date", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"2022 Read date", Order.Ascending}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Sorted Rows", {{"2022 Read date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Sorted Rows", {{"2022 Read date", type text}}, "en-US")[#"2022 Read date"]), "2022 Read date", "2022 Usage"),
    #"Sorted Rows1" = Table.Sort(#"Pivoted Column",{{"2023 Read Date", Order.Ascending}}),
    #"Pivoted Column1" = Table.Pivot(Table.TransformColumnTypes(#"Sorted Rows1", {{"2023 Read Date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Sorted Rows1", {{"2023 Read Date", type text}}, "en-US")[#"2023 Read Date"]), "2023 Read Date", "2023 Usage"),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Pivoted Column1", {"Customer", "Type", "Serial Number"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Date"}, {"Value", "Usage"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
    #"Sorted Rows2" = Table.Sort(#"Changed Type1",{{"Date", Order.Ascending}})
in
    #"Sorted Rows2"

 

2.Try code as below to create a measure.

 

Day_Avg_Usage = AVERAGEX(FILTER(ALLSELECTED('Table'),'Table'[Date]=MAX('Table'[Date])),[Usage])

 

Result is as below.

vweiyan1msft_1-1702897613181.png

 

Best Regards,

Yulia Yan

 

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

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.