Forum Discussion
Replicating an Excel table with calculated cells
Hi Gurus,
I have an excel table with cells. in each cell I have a round formula like the screenshot below and they get data from other tables in the same work sheet as you can see below. I know have problem with designing the same table with same calculated cells and dynamic so it can do all the same and finally I have the same values in my table to be able to use them for my next steps. The table is updated every day once:
I have the Excel file but I don't know how to share it here?!
Would appreciate your professional answers.
Thanks a lot
18 Replies
- AnonymousNot applicable
I would appreciate if a support team member can give a solution to this question I podted.
Thanks to all especially Zubair_Muhammad , jdbuchanan71 , MFelix
- MFelixSuper User
Hi Anonymous ,
Just a few question I have based on the spreadsheet you provided that I cannot be sure about how the connection is made between the data:
- Is the week value per each girl being filled in any of your data?
- In your file you have the total is based on a calculation that I assume is not totally exact see image below:
As you can see in the image taken from your excel file the Total sum all the weeks but also the columns N and Q believe this is not exact you only want to sum the weeks for the round up calculation. Is my assumption correct?
I also must tell you that based on the calculation you want to achieve it's better to do it in DAX measures since they can be reutilized and don't height on your model.
However it's possible to do it in M Language you need to do several steps and go back and forth on the steps but see the details below:
- Assuming you have two tables one with:
- Contestant | Canabi | SLSQ (values are the ones show above)
- Contestant | Girl | Week (values are the Weeks)
- Group Table Contestant by Contestant colum
- Canabi = Sum
- SLSQ = Sum
- Pivot Table Weeks
- Pivot should be done by column girl with values of week
- Group Table Weeks By contestant (this step should refer to the Table week step and not the Pivot step
- Merge the Pivot Table Step with the Group Table week step
- This merge must be done by contestant column
- Expand the column with total weeks value
- Unpivot the Previous table
- Get a new result with:
- Contestant | Total Week | Girl | Week
- Get a new result with:
- Merge Unpivot table with Contestant Group table
- This merge must be done by contestant column
- Expand SLSQ and Canabi Columns
- Add two new colums with the following code:
- Number.Round([Week]/[Total Week]*[Canabi])
- Number.Round([Week]/[Total Week]*[SLSQ])
The final outcome is the pivot column you need.
Check the code below and the PBIX file attach.
let Source = Excel.Workbook(File.Contents("C:\Users\mfelix\Downloads\recordheights.xlsx"), null, true), Contestant_Table = Source{[Item="Contestant",Kind="Table"]}[Data], Custom1 = Source{[Item="Contestant",Kind="Table"]}[Data], Custom2 = Source{[Item="Contestant",Kind="Table"]}[Data], Contestant_format = Table.TransformColumnTypes(Custom2,{{"Contestant", type text}, {"Canabi", Int64.Type}, {"SLSQ", Int64.Type}}), Contestant_Group = Table.Group(Contestant_format, {"Contestant"}, {{"Canabi", each List.Sum([Canabi]), type number}, {"SLSQ", each List.Sum([SLSQ]), type number}}), Weeks_Table = Source{[Item="Girls",Kind="Table"]}[Data], Weeks_Format = Table.TransformColumnTypes(Weeks_Table,{{"Contestant", type text}, {"Girl", type text}, {"Week", Int64.Type}}), Weeks_Pivot = Table.Pivot(Weeks_Format, List.Distinct(Weeks_Format[Girl]), "Girl", "Week", List.Sum), Weeks_Group = Table.Group(Weeks_Format, {"Contestant"}, {{"Total Week", each List.Sum([Week]), type number}}), Weeks_Merge_Total = Table.NestedJoin(Weeks_Pivot, {"Contestant"}, Weeks_Group, {"Contestant"}, "Total", JoinKind.LeftOuter), Weeks_Total_Expand = Table.ExpandTableColumn(Weeks_Merge_Total, "Total", {"Total Week"}, {"Total Week"}), Weeks_Unpivot = Table.UnpivotOtherColumns(Weeks_Total_Expand, {"Contestant", "Total Week"}, "Girl", "Week"), Weeks_Contest_Merge = Table.NestedJoin(Weeks_Unpivot, {"Contestant"}, Contestant_Group, {"Contestant"}, "SQLCANABIS", JoinKind.LeftOuter), Expand_Contestant_Columns = Table.ExpandTableColumn(Weeks_Contest_Merge, "SQLCANABIS", {"Canabi", "SLSQ"}, {"Canabi", "SLSQ"}), Canabi_Total_Column = Table.AddColumn(Expand_Contestant_Columns, "Total Canabi", each Number.Round([Week]/[Total Week]*[Canabi])), SLSQ_Total_Column = Table.AddColumn(Expand_Contestant_Columns, "Total Canabi", each Number.Round([Week]/[Total Week]*[SLSQ])) in SLSQ_Total_ColumCheck PBIX file and excel file attached.
Regards,
MFelix
- AnonymousNot applicable
MFelix Thanks for your detailed reply. I am sorry to get back later.
how did you import weeks table in the middle of editing Query?
Actually there was no weeks table but I produced it as a static table inside Power Query. Finally, I decided to use DAX formulas as you mentioned are so much straight but your proposed solution seems more useful in my case.
Would appreciate to correct my understanding that you did several input tables into the Contestant Table(my fact table)? if yes how? if not what are the Weeks table?
Thank you
- jdbuchanan71Super User
Anonymous wrote:I have the Excel file but I don't know how to share it here?!
You can share it by uploading it to your https://www.dropbox.com account.
- AnonymousNot applicable
jdbuchanan71 Thanks for the reply.
Here I shared the link to dropbox file I shared. If you have any problem let me know:
https://www.dropbox.com/s/22nirv4hbxx4wy1/recordheights.xlsx?dl=0
Looking forward to hearing from you
Thanks
- jdbuchanan71Super User
Anonymous
If this is going to be a PowerBI model we will need to see the .pbix file. We can't help without knowing the structure of the model to know things like how the Girls data is coming in. Please post a link to your Power BI file.