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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
TeresaBusby
Frequent Visitor

Convert DAX to Power M Query

First time trying to convert DAX to Power M Query and having a hard time getting started/finding exactly what I need in the help documents. Can someone help me convert this?  And are there any resources/cheat sheets to help do this?  For example "Calculate" in DAX is "X" in Power M, etc.

 

This is my DAX which gives me the count of Type's per Id.

 

CALCULATE (
    COUNTROWS ( 'Table' ) ,
    ALLEXCEPT (
        'Table' ,
        'Table'[ID],
        'Table'[Type]
    )
)
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @TeresaBusby 

You can use group by in power query to count rows, you can refer to the folloing link.

Group rows of data (Power Query) - Microsoft Support

You can put the following code to advanced editor in power query to as a sample

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpUitVBZyXBWclglhFc1gguawSRjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Type", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID", "Type"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

vxinruzhumsft_0-1696837320515.png

 

Best Regards!

Yolo Zhu

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @TeresaBusby 

You can use group by in power query to count rows, you can refer to the folloing link.

Group rows of data (Power Query) - Microsoft Support

You can put the following code to advanced editor in power query to as a sample

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpUitVBZyXBWclglhFc1gguawSRjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Type", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID", "Type"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"

vxinruzhumsft_0-1696837320515.png

 

Best Regards!

Yolo Zhu

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

mlsx4
Memorable Member
Memorable Member

Hi @TeresaBusby 

 

I'm not sure why you need to traslate a DAX to Power M Query. Anyway, in the official doc, you can find every formula for M language (https://learn.microsoft.com/en-us/powerquery-m/power-query-m-function-reference).

In the case of your formula, you may need a grouping function (https://radacad.com/grouping-in-power-query-getting-the-last-item-in-each-group)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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