Excel Power Query to pivot Rent Roll with lease charges - excel

I have a sample truncated rent roll below (actual is hundreds of lines long with different combinations of lease codes, vacancies, moveouts). There is some randomness to the data as there are vacancies which make "moveIn, LeaseEnd, moveOut" fields blank and sometimes there are moveOuts.
I would like to pivot the leaseCodes to separate columns as seen in the second image.
Is it possible to do this in power query without custom code? My initial thoughts were to do fill down on all of the fields except lease code and amount and then pivot the leaseCode Column with the Amount Column. But as you can see, I won't be able to do this because the date columns are sometimes blank due to vacancies or filled with moveouts.
Would really appreciate anyone's help on best way to navigate this.
Thank you,

Create Table1 by selecting data and using Data...From Table/Range [x] including headers. Right click unit column and Fill...Down... Select [unit, leaseCode, Amount] columns, right-click RemoveOtherColumns. Use the drop-box next to LeaseCode column header and uncheck (null) to get rid of those rows. Select leaseCode column then Transform...Pivot Column... and for value column use Amount. Do File ... Close and Load To ..... Only Create Connection. You should get something similar to this code (edited to replace datetime with date). Make sure this query is named Table1
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"unit", Int64.Type}, {"floorplan", type any}, {"unitArea", Int64.Type}, {"resident", type text}, {"tenant", type text}, {"marketRent", Int64.Type}, {"leaseCode", type text}, {"Amount", Int64.Type}, {"residentDeposit", Int64.Type}, {"otherDeposit", Int64.Type}, {"moveIn", type date}, {"leaseEnd", type date}, {"moveOut", type date}, {"balance", type any}}),
#"Filled Down" = Table.FillDown(#"Changed Type",{"unit"}),
#"Removed Other Columns" = Table.SelectColumns(#"Filled Down",{"unit", "leaseCode", "Amount"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each ([leaseCode] <> null)),
#"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[leaseCode]), "leaseCode", "Amount", List.Sum)
in #"Pivoted Column"
Back in normal excel, show Queries dialog box (if not already open) with Data...Queries and Connections... right click Table1 query and choose Duplicate. Delete every step after step 2 in the Applied Steps tab off to the right by right clicking step called "Filled Down" and using Delete until end. Use the drop-box next to [unit] column header and uncheck (null) to get rid of those rows. Select the [leaseCode, Amount] columns and right click Remove Columns to get rid of those two. Home...Merge Queries... and in the bottom drop down choose Table1 we created before. Click unit column in top section and then unit column in bottom section to link them. Join kind is left outer, the default. Hit OK. Click the double arrow atop the new column, uncheck unit, uncheck use original column name as prefix, then hit OK. Resort columns as needed. Change types as needed Close and load to table. Should generate code similar to
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"unit", Int64.Type}, {"floorplan", type any}, {"unitArea", Int64.Type}, {"resident", type text}, {"tenant", type text}, {"marketRent", Int64.Type}, {"leaseCode", type text}, {"Amount", Int64.Type}, {"residentDeposit", Int64.Type}, {"otherDeposit", Int64.Type}, {"moveIn", type date}, {"leaseEnd", type date}, {"moveOut", type date}, {"balance", type any}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([unit] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"leaseCode", "Amount"}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns",{"unit"},Table1,{"unit"},"Table1",JoinKind.LeftOuter),
#"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"mta", "watr", "Total", "garg"}, {"mta", "watr", "Total", "garg"})
in #"Expanded Table1"

In the Query Editor, highlight the lease code and amount columns and then pivot them (from the Transform tab on the Query Editor ribbon).

Related

Can Power Query tabularize data with different levels of sub-total detail?

I am a proficient Excel user but new to Power Queries - they seem powerful, but I am hung up tabularizing a Quickbooks report.
In short, the data includes several columns of hierarchy all expanded to the lowest node and includes sub-headers and sub-totals. I need to tabularize this data, but when one section has detail 3 columns deep and the next section only goes 2 columns deep, "Fill Down" (in the 3rd column) incorrectly fills sub-headers in a different section.
If this does not make sense, I put together a screenshot that hopefully illustrates this question a little better:
Thank you in advance,
Dillon
This is a PivotTable right?
Go to "Design" -> drop down "Report Layout" -> Show in Tabular Form
If what you are showing is not a pivot table, but rather the output from Quicken, then you can:
Fill Down Column 1 only
Group by Column 1
Use a custom aggregation to Fill down column 2 in each subtable
Then expand the subtables
Remove the Amount rows that contain null
reset the data types
let
//cahnge table name in next line to the real table name in your workbook
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"Column1", type text}, {"Column2", type text}, {"Item", type text}, {"Amount", Currency.Type}}),
//Fill down the main group
#"Filled Down" = Table.FillDown(#"Changed Type",{"Column1"}),
//group by Column 1; then fill down subgroup in column 2
group = Table.Group(#"Filled Down","Column1",{
{"subGroup", each Table.FillDown(_,{"Column2"})}
}),
#"Expanded subGroup" = Table.ExpandTableColumn(group, "subGroup", {"Column2", "Item", "Amount"}, {"Column2", "Item", "Amount"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded subGroup", each ([Amount] <> null)),
#"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"Column2", type text}, {"Item", type text}, {"Amount", Currency.Type}})
in
#"Changed Type1"

Writing a query that can have excel fill in and consolidate unpopulated fields within a group of duplicates?

I have a contact info dataset (large) that contains lots of semi-duplicate rows that I'd like to condense into as little rows as possible. Attached is a sample of what I'm talking about.
The blue table on the left is smaller scale example of what I'm currently working with. The orange table on the right is what I would like the table to look like.
I want to write a query that will be able to select an ID that has multiple rows, and within that selection, assess whether values can be moved into a parent row that has unpopulated cells (see ID "4" and how I condensed those three rows of data into one by filling in blanks and consolidating duplicates).
An important point of emphasis is how to perform this task without it being a blanket statement for all duplicates in the entire worksheet. Ultimately I want to perform this task for the entire worksheet, but I want excel to first isolate a single ID and then execute the aforementioned task, rather than evaluating the criteria based on all duplicate IDs. ((If that makes sense))
One other condition I would like to have is for certain columns where multiple rows under the same ID have different values, is to allocate that data into a subsequent column (see Tags & Tags2 columns under ID "1") instead of overriding a cell.
I only want to do this ^ for 2 columns; for the others, have it keep them as separate rows.
This sounds like a task for Power Query, but my knowledge is limited in that realm. Any help on how to construct a query that accomplish this task is much appreciated. Thanks.
This seems to work fine
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Title", type text}, {"Company", type text}, {"Phone", type text}, {"Phone2", type any}, {"Street Address", type any}, {"City", type text}, {"Tags", type text}}),
// group, then unpivot, remove duplicates
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Data", each Table.Distinct(Table.UnpivotOtherColumns(_, {"ID"}, "Attribute", "Value"), {"Attribute", "Value"}), type table}}),
// combine all the tags into one cell for later splitting
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Group([Data], {"ID", "Attribute"}, {{"Data", each Text.Combine([Value],","), type text}})),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Attribute", "Data"}, {"Attribute", "Data.1"}),
// replace null with Title to preserve rows with no data
#"Replaced Value" = Table.ReplaceValue(#"Expanded Custom",null,"Title",Replacer.ReplaceValue,{"Attribute"}),
#"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Data"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Attribute]), "Attribute", "Data.1"),
// split the Tags column into any number of columns as needed
#"Replaced Value1" = Table.ReplaceValue(#"Pivoted Column",null,"xxx",Replacer.ReplaceValue,{"Tags"}),
DynamicColumnList = List.Transform({1 ..List.Max(Table.AddColumn(#"Replaced Value1","Custom", each List.Count(Text.PositionOfAny([Tags],{","},Occurrence.All)))[Custom])+1}, each "Tags." & Text.From(_)),
#"Split Column by Delimiter" = Table.SplitColumn( #"Pivoted Column", "Tags", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), DynamicColumnList)
in #"Split Column by Delimiter"
You can get your desired output from Power Query using just the Table.Group function.
I have assumed:
Output columns are only as you show
Input columns don't have anything in Phone2 and Tags2
If that is not the case, simple modifications are possible
If there are more distinct entities that columns for the output, they will be output in a single column concatenated.
In other words, if you had three tags; the first one would be in the Tags column and the second and third concatenated with a comma in the Tags 2 column.
I did it this way because, since you show no examples, I'm not quite sure how you want things lined up if you have, for example, multiple phones and multiple tags.
Note: If you want to restrict this to just one ID, just insert a filtering step at the beginning
M Code
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Title", type text}, {"Company", type text}, {"Phone", type text}, {"Phone2", type any}, {"Street Address", type text}, {"City", type text}, {"Tags", type text}, {"Tags2", type any}}),
//Group by ID then
//Depending on how many columns available in results table, will
//either concatenate, multiple non-duplicate rows, or put them in separate columns
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {
{"Title", each Text.Combine(List.Distinct([Title]),", ")},
{"Company", each Text.Combine(List.Distinct([Company]),", ")},
{"Phone", each try List.RemoveNulls([Phone]){0} otherwise null},
{"Phone 2", each Text.Combine(List.RemoveFirstN(List.RemoveNulls(List.Distinct([Phone])),1),", ")},
{"City", each Text.Combine(List.Distinct([City]),", ")},
{"Tags", each try List.RemoveNulls([Tags]){0} otherwise null},
{"Tags 2", each Text.Combine(List.RemoveFirstN(List.RemoveNulls(List.Distinct([Tags])),1),", ")}
})
in
#"Grouped Rows"

Power Query Sum of column by group as new column

So I am new to power query and I just wasted over an hour looking for something that I can do easily in many other programs.
I just want to create a new column summing up another column. FOr instance, to check if the percentage a correct and if not normalize therafter. I dont want to group by and reduce the table.
I ve been searching left and right and tried to add a new column like "Group Sum" using stuff like
= list.sum([Number])
= Calculate(SUM([Number])
just to get the the total sum of all entries 200. No success.
Maybe its me, but I really dont see the logic.
I now tried
let
Quelle = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
#"Geänderter Typ" = Table.TransformColumnTypes(Quelle,{{"Group", type text}, {"Gender", type text}, {"Number", Int64.Type}, {"Group Sum", Int64.Type}, {"Spalte1", Int64.Type}})
#"Added Custom" = Table.AddColumn(#"Geänderter Typ","Group Sum",(i)=>List.Sum(Table.SelectRows(#"Geänderter Typ", each [Group]=i[Group])[Number]), type number )
in
#"Geänderter Typ"
which results in an error and
let
Quelle = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
#"Geänderter Typ" = Table.TransformColumnTypes(Quelle,{{"Group", type text}, {"Gender", type text}, {"Number", Int64.Type}, {"Group Sum", Int64.Type}}),
#"Hinzugefügte benutzerdefinierte Spalte" = Table.AddColumn(#"Geänderter Typ", "Benutzerdefiniert", each Table.Group(Quelle, {"Group"}, {{"Group Sum", each List.Sum([Number]), type nullable number}}))
in
#"Hinzugefügte benutzerdefinierte Spalte"
Which gives me a new column where all entries say "Table"
Here are two other options. The examples assume your source table is named Table1. Here's how mine looks at its source in Excel:
Note it does not have a Group Sum column. The query will derive that.
Option 1.
Click Add Column then Custom Column and fill out the screen like this and click OK:
You should see a table like this:
Then just click the table in the first row of the Custom column and you should get a table that looks like this:
Then you can merge this new table with the original source table (Table1). Click Home > Merge Queries and fill out the information for the merge like this and click OK. (Note that the same query "Table1" is being merged to itself at this point, and only the Group column is selected for each entry.)
You should see a table like this:
Then, in the formula bar above that table, where you see = Table.NestedJoin(Custom, {"Group"}, Custom, {"Group"}, "Custom", JoinKind.LeftOuter), change the first instance of Custom to Source, so the line reads = Table.NestedJoin(Source, {"Group"}, Custom, {"Group"}, "Custom", JoinKind.LeftOuter) instead.
That is, change it from:
To:
Then expand the new Custom column by clicking the button, only selecting the Group Sum column, clearing the checkbox beside "Use original column name as prefix," and clicking OK:
You should get this result:
Here's the M code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Gender", type text}, {"Number", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.Group(Source, {"Group"}, {{"Group Sum", each List.Sum([Number]), type nullable number}})),
Custom = #"Added Custom"{0}[Custom],
#"Merged Queries" = Table.NestedJoin(Source, {"Group"}, Custom, {"Group"}, "Custom", JoinKind.LeftOuter),
#"Expanded Custom" = Table.ExpandTableColumn(#"Merged Queries", "Custom", {"Group Sum"}, {"Group Sum"})
in
#"Expanded Custom"
(You can replace Table1, Source and Changed Type with Tablelle1, Quelle, and #"Geänderter Typ", respectively throughout the code above to align with Max's language.)
Option 2.
Click Transform then Group By and fill out the screen like this and click OK:
Then expand the AllData column with only the Gender and Number columns selected like this:
The result:
Here's the M code:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Group"}, {{"AllData", each _, type table [Group=text, Gender=text, Number=number]}, {"Group Sum", each List.Sum([Number]), type number}}),
#"Expanded AllData" = Table.ExpandTableColumn(#"Grouped Rows", "AllData", {"Gender", "Number"}, {"Gender", "Number"})
in
#"Expanded AllData"
try
let Quelle= Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
#"Promoted Headers" = Table.PromoteHeaders(Quelle, [PromoteAllScalars=true]),
#"Geänderter Typ" = Table.TransformColumnTypes(#"Promoted Headers",{{"Group", type text}, {"Gender", type text}, {"Number", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Geänderter Typ","Group Sum2",(i)=>List.Sum(Table.SelectRows(#"Geänderter Typ", each [Group]=i[Group]) [Number]), type number )
in #"Added Custom"
Group and Join Method
I have now seen a few ways to do this, but I think the most efficient is probably a group-and-join approach that builds on previous comments and answers here. It takes one line:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.Join(Source, "Group", Table.Group(Source,{"Group"},{{"Group Sum", each List.Sum([Number]), type nullable number}}), "Group")
in
#"Added Custom"
The Table.Group() part of this creates a table with each unique value of the grouping variable ("Group" here) and, for each of those unique values, its summary value (the sum of [Number] for all rows with the same "Group" value here). To attach these summary values onto the original table becomes the job for Table.Join(). The Table.Join() function gets four input arguments: 1.) the original table, 2.) the grouping column in the original table ("Group" here), 3.) the summary table (that's the output of the Table.Group() function here) and 4.) the grouping column in summary table (also "Group" here).
I tested this and get the results as shown:
Note: I changed Number column values from the question to show that the code is working. In the example provided in the original question, the Group Sum is 100 for both groups, and that seems to make the approach suggested in another answer look like it's working when it does not.

How to consolidate rows of data in excel

I am trying to consolidate rows when they have the same ID, Order, and Class. However, the consolidated row needs sum the length, AND input the correct begin and end. So the consolidated row will have the begin value of the first row, and the end value of the last row Please check the image to see what I mean.
I'm pretty sure I can achieve the summing of the length using SUMIF, but I can't figure out how to input the correct begin and end values into the consolidated row.
Is this even possible with excel? I can't use pivot tables because I'm not simply trying sum the length, I want the columns to remain the same, just to consolidate the rows accordingly. Any help will be much appreciated!
The left is what I have, the right is what I am trying to achieve:
In your example, it seems the begin and end that you want are the min and max respectively, and I used that in the approach.
Relatively simple to do with Power Query, which is available in Excel 2010+.
Select the ID, Order and Class columns
Group By
For Aggregations have min of begin; max of end; and sum of length
Move the Class column back to the end
Voila!
This can all be done quickly from the UI
M-Code
let
Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Order", Int64.Type}, {"begin", Int64.Type}, {"end", Int64.Type}, {"length", Int64.Type}, {"class", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID", "Order", "class"}, {{"Begin", each List.Min([begin]), type number}, {"End", each List.Max([end]), type number}, {"Length", each List.Sum([length]), type number}}),
#"Reordered Columns" = Table.ReorderColumns(#"Grouped Rows",{"ID", "Order", "Begin", "End", "Length", "class"})
in
#"Reordered Columns"
For completeness: If, perchance, you really need to use the First and Last Rows within each group for Begin and End, instead of Min/Max, you can use the following code.
In the group by step, instead of aggregating begin/end by max/min, you choose an aggregation of All Rows. This will create a table which includes the begin and end entries for each group. You can then extract the first and last entries using the List.First and List.Last functions.
The code for the custom columns:
List.First(Table.Column([#"Start/End"],"begin"))
List.Last(Table.Column([#"Start/End"],"end"))
M-Code
let
Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Order", Int64.Type}, {"begin", Int64.Type}, {"end", Int64.Type}, {"length", Int64.Type}, {"class", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID", "Order", "class"}, {{"Length", each List.Sum([length]), type number}, {"Start/End", each _, type table [ID=number, Order=number, begin=number, end=number, length=number, class=number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Begin", each List.First(Table.Column([#"Start/End"],"begin"))),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "End", each List.Last(Table.Column([#"Start/End"],"end"))),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Start/End"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ID", "Order", "Begin", "End", "Length", "class"})
in
#"Reordered Columns"
By the way, you can come pretty close with a regular Pivot Table (especially if you can use Min/Max for the begin/end). It's not as flexible, though, and I don't think you can order the columns the way you have shown.
Below is a simple pivot table.
You drag ID, Order and class to the Rows area.
You drag Begin, End and Length to the Values area applying Min, Max and Sum.
Then Show the layout in Tabular form; turn off the grand totals and subtotals, and you have:
Option with formulas - in the simplest way, copy the table to a new location and use Remove duplicates to leave unique values in the Id, Order, and Class columns. Next fill the columns with the following formulas:
Begin (array formula):
{=INDEX($C$2:$C$9,MIN(IF(($A$2:$A$9=H2)*($B$2:$B$9=I2)*($F$2:$F$9=M2),ROW($A$2:$A$9)-MIN(ROW($A$2:$A$9))+1)),0)}
End (array formula):
{=INDEX($D$2:$D$9,MAX(IF(($A$2:$A$9=H2)*($B$2:$B$9=I2)*($F$2:$F$9=M2),ROW($A$2:$A$9)-MIN(ROW($A$2:$A$9))+1)),0)}
Length (conventional formula):
=SUMPRODUCT($E$2:$E$9*($A$2:$A$9=H2)*($B$2:$B$9=I2)*($F$2:$F$9=M2))
Array formulas after editing is confirmed by pressing ctrl + shift + enter

Scan worksheet for missing items per ID

I have a worksheet with IDs of people visiting on certain days.
Simple example.
I want to scan all IDs to check if they have missed a visit day. When visit day 1, 2, 3, 4 and 5 are obligated.
I can't add code to this database, because it is locked (it is a worksheet with confidential info).
I don't know where to start.
The following solution is using Power Query which is available in Excel 2010 Professional Plus and all later versions of Excel. My demonstration is using Excel 365.
Suppose you have two tables:
Table1 is called Tbl_Visitday which is the 2-Column table in your example;
Table2 is called Rng_Obligated which is a 1-Column table containing all obligated days.
Go to Data tab in your Excel ribbon, use From Table function to add both tables to the power query editor one by one. When you access the editor for the first time, make sure set up the Query Options as below to avoid loading every query to a new worksheet;
Once you have added both tables to the editor, make a duplicate of Tbl_Visitday in the Queries section on the left hand side as shown below:
Let's work on Rng_Obligated first, highlight the column, use Transpose function under the Transform tab to transpose the data from rows to columns, then use Merge Columns function to merge all columns by delimiter semicolon ;, then you should have something like the following:
Let's move to Tbl_Obligated(2), remove the Visitday column, remove duplicates within the ID column and sort it ascending, then you should have:
Use Append Queries function under the Home tab to append Rng_Obligated table to the current table, and then right click the Merged column header and choose Fill -> Up to quickly fill the merged column with the same string, then you should have something like follow:
Filtered the ID column to hide null, then use the Split Columns function under the Transform tab to split the Merged column by delimiter semicolon ;, and in the advanced options to choose to put the results into Rows as shown below:
Use Merge Queries function under the Home tab to merge Tbl_Visitday table with the current table by holding the Ctrl key and select the first and second column consecutively in each table as shown below:
Expand the newly merge column to show Visitday column only, add a custom column using this formula =[Merged]=[Visitday], then filter the Custom column to show FALSE results only, then you should have:
Change the format of the Merged column to Text, then use Group By function under the Transform tab to group the Merged column by ID as shown below, the result will be error which is expected:
Go back to the last step in the APPLIED STEPS section on the right hand side, go to the formula bar and replace this part of the formula List.Sum([Merged]) with Text.Combine([Merged],","), hit enter and you will notice the error have become a text string as shown below:
You can close and load the query which will be created as a connection if you have amended the query setting in the first step. You can click Queries & Connections under the Data tab and right click the query and choose to load it to a specific location in your workbook.
In your case, you will need to ask the owner of the shared workbook to unlock the workbook so you can use the power query editor and load the output. Alternatively you can copy and paste the data to a new workbook where you can execute the power query to obtain the result.
Power Query allows you to update your source tables and recalculate the output (once you choose to refresh the data) in the back-end normally in a few seconds. If you do not want the output to be refreshed, you can copy and paste the output to a new table so the results stay unchanged.
Here are the power query M Code for the two tables for your reference. Let me know if you have any questions. Cheers :)
Rng_Obligated
let
Source = Excel.CurrentWorkbook(){[Name="Rng_Obligated"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"obligated", Int64.Type}}),
#"Transposed Table" = Table.Transpose(#"Changed Type"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Transposed Table", {{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}}, "en-AU"),{"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7"},Combiner.CombineTextByDelimiter(";", QuoteStyle.None),"Merged")
in
#"Merged Columns"
Tbl_Visitday(2)
let
Source = Excel.CurrentWorkbook(){[Name="Tbl_Visitday"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Visitday", type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Visitday"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Columns"),
#"Sorted Rows" = Table.Sort(#"Removed Duplicates",{{"ID", Order.Ascending}}),
#"Appended Query" = Table.Combine({#"Sorted Rows", Rng_Obligated}),
#"Filled Up" = Table.FillUp(#"Appended Query",{"Merged"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([ID] <> null)),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Filtered Rows", {{"Merged", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Merged"),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1",{"ID", "Merged"},Tbl_Visitday,{"ID", "Visitday"},"Table6",JoinKind.LeftOuter),
#"Expanded Table6" = Table.ExpandTableColumn(#"Merged Queries", "Table6", {"Visitday"}, {"Visitday"}),
#"Added Custom" = Table.AddColumn(#"Expanded Table6", "Custom", each [Merged]=[Visitday]),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom", each ([Custom] = false)),
#"Changed Type2" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Merged", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type2", {"ID"}, {{"MissedDay", each Text.Combine([Merged],","), type text}})
in
#"Grouped Rows"

Resources