Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi all,
I have a table with daily sales information, where product categories are in rows and days of the month are in columns.
My goal is to get each category's percentege of sales by day of the month. The last column is a list.sum of each day of sales of the respective category.
The best solution I got to achieve that is to add multiple columns dividing each category's day of sales by its total sales of the month and I'm trying to do that using list.accumulate.
The code I'm using is the following:
columns = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
added = List.Accumulate(columns, #"Added Custom", (tab,col) =>
Table.AddColumn(tab, Number.ToText(col) & "p", each if [col] <= 0 then 0 else [col]/[Total], Percentage.Type))
But it isn't working.
I also tried input the column names as text but it didn't work either.
My understanding is that I'm doing something wrong after the each. Can someone, please, give a hand with that?
Thankss
Solved! Go to Solution.
Hi @diogoricciardi ,
this sounds like a calculation that should better be performed dynamically with DAX.
But if you really need to do it in the query editor in M, you should consider unpivoting the days columns (check the columns that should be kept and select: Unpivot other columns). Then you have just 2 columns to divide against each other.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi @diogoricciardi ,
this sounds like a calculation that should better be performed dynamically with DAX.
But if you really need to do it in the query editor in M, you should consider unpivoting the days columns (check the columns that should be kept and select: Unpivot other columns). Then you have just 2 columns to divide against each other.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi Imke,
That actually helped a lot. I can't believe I didn't see it hehe.
One of the last steps in my query was pivoting the table so the days would be in columns. So what I did was to calculate the percentages before pivoting it and it worked beautifully.
Thanks a lot, I appreciate it.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 5 | |
| 5 |