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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Change the code below from DAX to Power Query

Hello Community

 

I found this code for dax, where the measure calculates the average days for the same id in multiple rows.

It works with DAX but I would like to do the same in Power Query, so that I can do the change in the data transformation.

 

 

Avg Activation Time =
var Oppy_id = 'Calculation'[Reference number]

Return
AVERAGEX( FILTER(ALL('Calculation'), 'Calculation'[Reference number] = Oppy_id), 'Calculation'[Activation (wd)])

 

Thanks a lot!

6 REPLIES 6
wdx223_Daniel
Community Champion
Community Champion

NewStep=Table.Group(PreviousStepName,"Reference Number",{"Avg Activation Time", each List.Average(List.RemoveNulls([#"Activation (wd)"]))})

Anonymous
Not applicable

Hi @Anonymous ,

 

Could you please share some screenshots /your applied steps / sample data to help us clarify your scenario?

 

Best Regards,
Eyelyn Qin

Anonymous
Not applicable

Hi @Anonymous ,

 

Please firstly use Group by:

Eyelyn9_0-1648536518085.png

Then expand necessary columns:

Eyelyn9_1-1648536564388.png

 

Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0UIrVgTAt4SwLOMsczHICsszgLFM4ywTMcgayjOEsIzDLBWS0UmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Reference number" = _t, #"Activation (wd)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Reference number", type text}, {"Activation (wd)", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Reference number"}, {{"All", each _, type table [Reference number=nullable text, #"Activation (wd)"=nullable number]}, {"Average", each List.Average([#"Activation (wd)"]), type nullable number}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Activation (wd)"}, {"Activation (wd)"})
in
    #"Expanded All"

 

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

Anonymous
Not applicable

Thanks a lot, this works but when I expand all the other columns than the group by function doesn't work anymore and I get rows with the same Reference number.. How can I solve this?

Anonymous
Not applicable

And furthermore it also counts blanks rows for the average which is not the right solution for me 😞

 

johnt75
Super User
Super User

Group by the [Reference number column] and create an average of [Activation (wd)]. Then restore the previous step to bring the full table back and add a new column grabbing the value from the step you inserted.

Helpful resources

Announcements
Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.