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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
paulfink
Post Patron
Post Patron

Power Query Calculation Help

Hi Guys,

 

need some help with Power Query M Code as im new to it.

 

I want to make some columns and it has to be in Power Query as i need to ammend this into another table.

 

I want to make columns using these DAX formulas but alter them to M Code:

REV - VAL = 
VAR
REV = CALCULATE(SUM('Table1'[Value]), FILTER('Table1', 'Table1'[Name] = "Rev"))

VAR
VAL = CALCULATE(SUM('Table1'[Value]), FILTER('Table1', 'Table1'[Name] = "Val"))

Return
+REV - Direct

 

Value1 = [REV - VAL] / CALCULATE(SUM('Table1'[Value]), FILTER('Table1', 'Table1'[Name] = "Name1"))

 

Value2 = [Value1] - CALCULATE(SUM('Table1'[Value]), FILTER('Table1', 'Table1'[Name] = "Name2"))

 

How can i replicate these measures into M Code?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @paulfink ,'

 

I have built a simply data sample with your DAX code:

data sample with DAX.PNG

 

Please use the below codes(List.Sum function) to create Custom columns:

 

Rev=let _item = [Name] in List.Sum(Table.SelectRows(#"Changed Type", each [Name] = "Rev")[Value])
Val= let _item = [Name] in List.Sum(Table.SelectRows(#"Rev", each [Name] = "Val")[Value])

 

...

Sum for Rev.PNG

 

After doing all sum for each Name, the table will be like this:

All sum for each name.PNG

Then:

add custom columns.PNG

The final output is shown below:

Add columns in power query.PNG

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.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @paulfink ,'

 

I have built a simply data sample with your DAX code:

data sample with DAX.PNG

 

Please use the below codes(List.Sum function) to create Custom columns:

 

Rev=let _item = [Name] in List.Sum(Table.SelectRows(#"Changed Type", each [Name] = "Rev")[Value])
Val= let _item = [Name] in List.Sum(Table.SelectRows(#"Rev", each [Name] = "Val")[Value])

 

...

Sum for Rev.PNG

 

After doing all sum for each Name, the table will be like this:

All sum for each name.PNG

Then:

add custom columns.PNG

The final output is shown below:

Add columns in power query.PNG

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.

Wow thats amazing, is it possible to have blank cells that dont relate to the filtered names? just so i can merge into one column

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.