Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
So this is my first post in this kind of community, since I'm really stuck. I'm quit new to Power Query Editor and need to convert two measures. 😅
The goal is to create a new column in the query editor and use it as a filter for the whole report. First I need two columns for the average price of the current year and the past year: for example here is the DAX-formular for the current year.
Solved! Go to Solution.
Hi @Etienne_1995,
According to your formula, I create a sample and get the result:
If you want to perform the result in M language, here's my solution. Add a custom column.
let
price_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_price_EW]),
quantity_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_quantity])
in
price_current_year/quantity_current_year
Result:
Here's the whole M syntax, you can copy-paste in a blank query to see the details.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdBLCsMwFEPRvXgcqCV/Yq8lZP/baPvkhlQtxpOTYNA9jsRMPF4nbel9W07ntpShNC2hxbSGVtMW2kx7aDfd/74wQofpDJ2myJqR3dc83wcNxPdCfmqUeOvm6/fqriJo7mqC7q4q2N3VBcNdZTDd1YbZXXUI99WH/PmgxbwWn08=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ERBK_Date = _t, ERBP_quantity = _t, ERBP_price_EW = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ERBK_Date", type date}, {"ERBP_quantity", Int64.Type}, {"ERBP_price_EW", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let price_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_price_EW]),quantity_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_quantity])in price_current_year/quantity_current_year)
in
#"Added Custom"
I also attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Etienne_1995,
According to your formula, I create a sample and get the result:
If you want to perform the result in M language, here's my solution. Add a custom column.
let
price_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_price_EW]),
quantity_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_quantity])
in
price_current_year/quantity_current_year
Result:
Here's the whole M syntax, you can copy-paste in a blank query to see the details.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdBLCsMwFEPRvXgcqCV/Yq8lZP/baPvkhlQtxpOTYNA9jsRMPF4nbel9W07ntpShNC2hxbSGVtMW2kx7aDfd/74wQofpDJ2myJqR3dc83wcNxPdCfmqUeOvm6/fqriJo7mqC7q4q2N3VBcNdZTDd1YbZXXUI99WH/PmgxbwWn08=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ERBK_Date = _t, ERBP_quantity = _t, ERBP_price_EW = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ERBK_Date", type date}, {"ERBP_quantity", Int64.Type}, {"ERBP_price_EW", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let price_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_price_EW]),quantity_current_year =List.Sum(Table.SelectRows(#"Changed Type",(x)=>Date.Year(x[ERBK_Date])=Date.Year(Date.From(DateTime.LocalNow())))[ERBP_quantity])in price_current_year/quantity_current_year)
in
#"Added Custom"
I also attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
NewStep=let a=Table.Buffer(Table.Group(Table.SplitColumn(ETL_Savings,"ERBK_Date",each {_,Date.Year(_)},{""ERBK_Date","Year"}),{"OtherKey1","OtherKey2","Year"},{"AveragePrice",each List.Sum([ERBP_price_EW])/List.Sum([ERBP_quantity])})),b=Date.Year(DateTime.LocalNow()) in Table.FromRecords(Table.TransformRows(ETL_Savings,each _&[AvergePriceCurrentYear=a{[OtherKey1=[OtherKey1],OtherKey2=[OtherKey2],Year=b]}?[AveragePrice]?,AvergePriceLastYear=a{[OtherKey1=[OtherKey1],OtherKey2=[OtherKey2],Year=b-1]}?[AveragePrice]?]))
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 8 | |
| 7 |