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
mochabits
Helper II
Helper II

How to create an aggregated table from an existing table using M language

Hi,

 

I have a table - MemberJoin in Power BI which looks like below:
MemberJoinTable.PNG

 

And I want to create an aggregated table from MemberJoin using M language. Is it doable? If yes, how to do it in M?

 

The corresponding SQL statement is below, and it's followed by a screenshot of what the new table should look like.

 

select [YTD Flag], [Member Type], year([Join Date]) "Year", MONTH([Join Date]) "Month", datename(MONTH, [Join Date]) "MonthName",
[Join Channel],  COUNT(*) "Count", 
cast(count([YTD Flag]) as float) / cast(sum(count([YTD Flag])) over (partition by year([Join Date])) as float) "Prcnt by Year"
from [MemberJoin]
group by [YTD Flag], [Member Type], [Join Channel], year([Join Date]), MONTH([Join Date]), datename(MONTH, [Join Date]) 
order by [YTD Flag] desc, [Member Type] desc, Year desc, Month, [Join Channel]
;

 

 

2018-07-15_13-19-49.jpg

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @mochabits,

 

On the advance query you need to do a group by and select all the fields you want to keep in your table and then select the one that you want to count.

 

Check this link and view the part about group rows.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @mochabits,

 

On the advance query you need to do a group by and select all the fields you want to keep in your table and then select the one that you want to count.

 

Check this link and view the part about group rows.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.