I want to create a Canadian holiday calendar for multiple years. For this, I'm using canada-holidays.ca/api. The thing is, if I want multiple years, I need to create a request for each year and then append them but doing so create a lot of requests that I don't want or need.
That's why I'm trying to integrate multiple source at the same time in a single query in Power Query.
I found this post as an inspiration for what I want to do but it is based on Excel so it needs to be adjusted a bit.
That's why, I wrote this code :
let
//2021 Holidays
Source1 = Json.Document(Web.Contents("https://canada-holidays.ca/api/v1/holidays?year=2021")),
#"Converti en table1" = Table.FromRecords({Source1}),
#"ExpandList1" = Table.ExpandListColumn(#"Converti en table1", "holidays"),
#"ExpandRecord1" = Table.ExpandRecordColumn(#"ExpandList1", "holidays", {
"id",
"date",
"nameEn",
"nameFr",
"federal",
"observedDate"}, {
"id",
"date",
"nameEn",
"nameFr",
"federal",
"observedDate"}),
#"Type modifié1" = Table.TransformColumnTypes(#"ExpandRecord1",{
{"id", Int64.Type},
{"date", type date},
{"nameEn", type text},
{"nameFr", type text},
{"federal", Int64.Type},
{"observedDate", type date}}),
#"Lignes filtrées1" = Table.SelectRows(#"Type modifié1", each (
[nameEn] = "Boxing Day" or
[nameEn] = "Canada Day" or
[nameEn] = "Christmas Day" or
[nameEn] = "Day of Mourning for Queen Elizabeth II" or
[nameEn] = "Easter Monday" or
[nameEn] = "Good Friday" or
[nameEn] = "Labour Day" or
[nameEn] = "National Day for Truth and Reconciliation" or
[nameEn] = "New Year’s Day" or
[nameEn] = "Remembrance Day" or
[nameEn] = "Saint-Jean-Baptiste Day" or
[nameEn] = "Thanksgiving" or
[nameEn] = "Victoria Day")),
//2022 Holidays
Source2 = Json.Document(Web.Contents("https://canada-holidays.ca/api/v1/holidays?year=2022")),
#"Converti en table2" = Table.FromRecords({Source2}),
#"ExpandList2" = Table.ExpandListColumn(#"Converti en table2", "holidays"),
#"ExpandRecord2" = Table.ExpandRecordColumn(#"ExpandList2", "holidays", {
"id",
"date",
"nameEn",
"nameFr",
"federal",
"observedDate"}, {
"id",
"date",
"nameEn",
"nameFr",
"federal",
"observedDate"}),
#"Type modifié2" = Table.TransformColumnTypes(#"ExpandRecord2",{
{"id", Int64.Type},
{"date", type date},
{"nameEn", type text},
{"nameFr", type text},
{"federal", Int64.Type},
{"observedDate", type date}}),
#"Lignes filtrées2" = Table.SelectRows(#"Type modifié2", each (
[nameEn] = "Boxing Day" or
[nameEn] = "Canada Day" or
[nameEn] = "Christmas Day" or
[nameEn] = "Day of Mourning for Queen Elizabeth II" or
[nameEn] = "Easter Monday" or
[nameEn] = "Good Friday" or
[nameEn] = "Labour Day" or
[nameEn] = "National Day for Truth and Reconciliation" or
[nameEn] = "New Year’s Day" or
[nameEn] = "Remembrance Day" or
[nameEn] = "Saint-Jean-Baptiste Day" or
[nameEn] = "Thanksgiving" or
[nameEn] = "Victoria Day")),
#"TableAppend" = Table.Combine({#"Lignes filtrées1"}, {#"Lignes filtrées2"})
in
#"TableAppend"
Sadly, I have this error when I try to run it : "Expression.Error: The columns parameter must be null, specify the number of columns, specify a list of column names, or specify a table type.
Details:
[List]"
So, is there anyone who have an idea of what I can do to integrate multiple sources and append them in a single request?
This is a very common problem:
Create a Parameter for Year and set it to 2021
Reference that parameter in your query for one year
Let PowerQuery create a Custom function from the result (right-click Create Function).
Enter all the years you are interested in a year column in another query
Add a new column by invoking your custom function and use the year column as parameter.
Expand the resulting tables and you're done
Read more about Using custom functions in the official documentation.
This is how your GetHolidays custom function should look like:
(Year as text) =>
let
Source1 = Json.Document(
Web.Contents(
"https://canada-holidays.ca/api/v1/holidays?year=" & Year
)
),
#"Converti en table1" = Table.FromRecords({Source1}),
#"ExpandList1" = Table.ExpandListColumn(#"Converti en table1", "holidays"),
#"ExpandRecord1" = Table.ExpandRecordColumn(#"ExpandList1", "holidays", {
"id",
"date",
"nameEn",
"nameFr",
"federal",
"observedDate"}, {
"id",
"date",
"nameEn",
"nameFr",
"federal",
"observedDate"}),
#"Type modifié1" = Table.TransformColumnTypes(#"ExpandRecord1",{
{"id", Int64.Type},
{"date", type date},
{"nameEn", type text},
{"nameFr", type text},
{"federal", Int64.Type},
{"observedDate", type date}}),
#"Lignes filtrées1" = Table.SelectRows(#"Type modifié1", each (
[nameEn] = "Boxing Day" or
[nameEn] = "Canada Day" or
[nameEn] = "Christmas Day" or
[nameEn] = "Day of Mourning for Queen Elizabeth II" or
[nameEn] = "Easter Monday" or
[nameEn] = "Good Friday" or
[nameEn] = "Labour Day" or
[nameEn] = "National Day for Truth and Reconciliation" or
[nameEn] = "New Year’s Day" or
[nameEn] = "Remembrance Day" or
[nameEn] = "Saint-Jean-Baptiste Day" or
[nameEn] = "Thanksgiving" or
[nameEn] = "Victoria Day"))
in
#"Lignes filtrées1"
And this is your Holiday Calendar for all available years 2017-2026:
let
Source = Table.FromList({2017 .. 2026}, Splitter.SplitByNothing(), {"Year"}),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", type text}}),
#"Invoked Custom Function" = Table.AddColumn(
#"Changed Type", "GetHolidays", each GetHolidays([Year])),
#"Expanded GetHolidays" = Table.ExpandTableColumn(
#"Invoked Custom Function",
"GetHolidays",
{"id", "date", "nameEn", "nameFr", "federal", "observedDate"},
{"id", "date", "nameEn", "nameFr", "federal", "observedDate"}
)
in
#"Expanded GetHolidays"
Related
I would like to know how to create the last column, Audit. To determine whether it is Included or Not Included the sum of any rows in "Average meeting per Day" within the same Employee/Day should match the "Actual Meeting" the employee attended.
I've taken this as an Example dataset -
Further, use Group By and Conditional column to have the Audit added.
Group by -
Conditional Column -
Result -
Code -
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s3PS0msVNJRMgRiAz1TMGkEJBOVYnVwSBtjShuBJQzhZBJYOqQ0tRhZuwlcHqg9=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Day = _t, Emp_ID = _t, #"Actual Meeting" = _t, #"Average Meeting/Day" = _t, Emp_Name = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Day", type text}, {"Emp_ID", Int64.Type}, {"Actual Meeting", type number}, {"Average Meeting/Day", type number}, {"Emp_Name", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Day", "Emp_ID"}, {{"Sum of avg", each List.Sum([#"Average Meeting/Day"]), type nullable number}, {"Actual Meeting", each List.Min([Actual Meeting]), type nullable number}}),
#"Added Conditional Column" = Table.AddColumn(#"Grouped Rows", "Audit", each if [Actual Meeting] = [Sum of avg] then "Included" else "Not Included")
in
#"Added Conditional Column"
Not sure this is going to help, but here goes. Note: not set up to work with duplicate values among the potential items to analyze. No idea if it will work with so many decimals, so that the sum of the decimals might be 0.0000001 off from total and thus not be recognized. Works for me with whole numbers
let
Process=(x as table) as table =>
// Bill Szysz 2017, all combinations of items in list, blows up with too many items to process due to large number of combinations
let ComboList=x[AMD],
find=x[AM]{0},
Source=Table.FromList(List.Transform(ComboList, each Text.From(_))),
AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1),
ReverseIndeks = Table.AddIndexColumn(AddIndex, "RevIdx", Table.RowCount(AddIndex), -1),
Lists = Table.AddColumn(ReverseIndeks, "lists", each
List.Repeat(
List.Combine({
List.Repeat({[Column1]}, Number.Power(2,[RevIdx]-1)),
List.Repeat( {null}, Number.Power(2,[RevIdx]-1))
})
, Number.Power(2, [Index]))
),
ResultTable = Table.FromColumns(Lists[lists]),
#"Replaced Value" = Table.ReplaceValue(ResultTable,null,"0",Replacer.ReplaceValue,Table.ColumnNames(ResultTable )),
#"Added Index" = Table.AddIndexColumn(#"Replaced Value", "Index", 0, 1, Int64.Type),
totals = Table.AddColumn(#"Added Index", "Custom", each List.Sum(List.Transform(Record.ToList( Table.SelectColumns(#"Added Index",Table.ColumnNames(ResultTable )){[Index]}) , each Number.From(_)))),
#"Filtered Rows" = Table.SelectRows(totals, each ([Custom] = find)),
#"Kept First Rows" = Table.FirstN(#"Filtered Rows",1),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Kept First Rows", {"Custom", "Index"}, "Attribute", "Value"),
#"Filtered Rows1" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "0")),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows1",{"Value"}),
FoundList = Table.TransformColumnTypes(#"Removed Other Columns",{{"Value", type number}}),
#"Merged Queries" = Table.NestedJoin(x, {"AMD"}, FoundList, {"Value"}, "output1", JoinKind.LeftOuter),
#"Expanded output1" = Table.ExpandTableColumn(#"Merged Queries", "output1", {"Value"}, {"Value"}),
#"Calculated Absolute Value" = Table.TransformColumns(#"Expanded output1",{{"Value", each if _=null then "Not Included" else "Included", type text}})
in #"Calculated Absolute Value",
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Day", type text}, {"Employee_ID", Int64.Type}, {"AM", Int64.Type}, {"AMD", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Day", "Employee_ID"}, {{"data", each _, type table [Day=nullable text, Employee_ID=nullable number, AM=nullable number, AMD=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Process([data])),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Day", "Employee_ID", "AM", "AMD", "Value"}, {"Day", "Employee_ID", "AM", "AMD", "Value"})
in
#"Expanded Custom"
Hello I need help removing duplicate rows under certain conditions.
Raw File
ANI
Date
Time
111-111-1111
8/7/2022
10:34:00 AM
111-111-1111
8/7/2022
12:00:00 PM
111-111-1111
8/7/2022
12:03:00 PM
222-222-2222
8/8/2022
10:50:00 AM
222-222-2222
8/8/2022
10:52:10 AM
333-333-3333
8/9/2022
12:29:00 PM
333-333-3333
8/9/2022
12:32:00 PM
333-333-3333
8/9/2022
12:33:00 PM
444-444-4444
8/10/2022
1:50:00 PM
444-444-4444
8/10/2022
1:51:00 PM
Raw File contains ANI column which shows different phone numbers called into my system,
Date and Time columns matching the time which the calls came in.
I want to remove the earliest entries of the back-to-back calls based on the same number and date only if called in within 3 minutes after the initial call.
This is the end result that I wish to my Power BI would see and count:
Result
ANI
Date
Time
111-111-1111
8/7/2022
10:34:00 AM
111-111-1111
8/7/2022
12:03:00 PM
222-222-2222
8/8/2022
10:52:10 AM
333-333-3333
8/9/2022
12:33:00 PM
444-444-4444
8/10/2022
1:51:00 PM
At the end, I want it to count the back-to-back calls just once if called in within 3 min time frame and leave alone singular calls made outside of that condition.
Please help.
Here is another way of doing this using the Query Editor:See the comments to help understand the algorithm
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc8xCoAwDIXhq0hni8lLRO3mAQT30vtfw1qiZCodfsjwwSM5B2aOFoc57Mu2gIB6MiXRRDSdVyhzV6KyV94jUpwEEC00ubv1ldx6XyLxL0UkWtLk4dZxuPWuFAxL/5GqRkubZPqpfTQk+ZPlAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ANI = _t, Date = _t, Time = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ANI", type text}, {"Date", type date}, {"Time", type time}}),
//create a column with the combine datetime
#"Added Custom" = Table.AddColumn(#"Changed Type", "DateTime", each [Date]&[Time], type datetime),
//group by ANI
// for each ANI group
// Sort by datetime
// Add a shifted column to compare one row to the next
// Retain only those rows where the difference between the original and the next column is greater than 3 minutes
// or the last row which will have a null in the shifted column
#"Grouped Rows" = Table.Group(#"Added Custom", {"ANI"}, {
{"Filtered", (t)=>
let
sorted = Table.Sort(t,{"DateTime", Order.Ascending}),
shifted = Table.FromColumns(
Table.ToColumns(t) & {List.RemoveFirstN(t[DateTime],1) & {null}},
type table[ANI=text, Date=date, Time=time, DateTime=datetime, Shifted=datetime]),
deleteRows = Table.SelectRows(shifted, each [Shifted] = null or Duration.TotalMinutes([Shifted] - [DateTime]) > 3)
in
deleteRows, type table[ANI=text, Date=date, Time=time]}
}),
//re-expand the groups
#"Expanded Filtered" = Table.ExpandTableColumn(#"Grouped Rows", "Filtered", {"Date", "Time"})
in
#"Expanded Filtered"
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lc8xCoAwDIXhq0hnS5OXiNrNAwju4v2voaVRs1WHHzJ8w8u+B2aOFnehD1MaEwgoN1MWzUTdsoajb1hcsNjtmxVnAUQL1U5+w0BuQ8si82NFJFpS7ew3YHYbGlbww/rfVDVaWi3Ti+23j5Zve5w=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ANI = _t, Date = _t, Time = _t]),
#"Merged Columns" = Table.CombineColumns(Source,{"Date", "Time"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Changed Type with Locale" = Table.TransformColumnTypes(#"Merged Columns", {{"Merged", type datetime}}, "en-US"),
#"Sorted Rows" = Table.Sort(#"Changed Type with Locale",{{"ANI", Order.Ascending}, {"Merged", Order.Descending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each
try
if [ANI] = #"Sorted Rows"[ANI]{[Index] - 1} and #"Sorted Rows"[Merged]{[Index] - 1} -[Merged] <= #duration(0,0,3,0) then true else false
otherwise false
),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Custom"}),
#"Inserted Date" = Table.AddColumn(#"Removed Columns", "Date", each DateTime.Date([Merged]), type date),
#"Inserted Time" = Table.AddColumn(#"Inserted Date", "Time", each DateTime.Time([Merged]), type time),
#"Removed Columns1" = Table.RemoveColumns(#"Inserted Time",{"Merged"})
in
#"Removed Columns1"
i've got a datasheet with a bunch of tasks, their start/end time, duration and start day.
Task
Start Time
End Time
Duration
Start Day
Task1
21:00
22:15
1:15
Monday
Task1
21:20
23:30
2:10
Monday
Task2
23:00
23:20
0:20
Tuesday
What I'm trying to do is put this data into a new calculated table that would split each task and plot a new row for the mins spent in each hour, as determined by the duration. For example:
Task
Hour
Mins in Hour
Start Day
Task1
21
60
Monday
Task1
22
15
Monday
Task1
21
40
Monday
Task1
22
60
Monday
Task1
23
30
Monday
Task2
23
20
Tuesday
I'm having no luck, could anyone help please?
Can be done with PQ
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tZg9bhwxDIXv4tqFSEkzs3uHVHFnuDCQVAGSwnCR20cSn2YkhtLsxk5FwP6WoB5/xNHz88PT69sPenh8YHf1TmxYknXuStk+vX9/+/b6++HlUVgWhgpL15ito2twY9a55jcO9oStMQQrBt+z7iJssZoN6W90UWcj+2xgS3zJMvzSxK+rLM7G1tk0i7PxJIbb/W5ytmoddBmwVHORc+746mjMOvh1Hn79iF2vIUK7KPr6YQwr/K435O3fWDkbzmiyC+JNdoVfHrOib7LwO9ZsQe0kPTbosI1ZB78BfoPl17M6XMDhsv3y6+eMdWDdLWybZJNtRLuc+T1Ei4iBJ2wVTdg0TCZsFa1rohM2RmGLPfOLZBRrshFnS5rVYh/6jfAbrwx9eahvw040y2FRQCoO1F+GqEQbJMqcNSPa+1FCrFILZAYQBXXw6tr+0RIodFa54Q63d7MerO/bUrElYSzTLttl7HYDgggYg5cM9CKoU6hVih3K/chT6NKjs0bXKDfD8QSdCFtQXAnZngVwFyopSChipXWIOniNmPnRQDn/jbCjZJYwkqwi2IQVv26qQdklWra9q3Uhlv9hZ0k2TJIrdxL2hWzrfWacTSRq2A3sZrC+YfNoKhNhMSdCaZxb/UbFznRYFDsbCoXFfpPYbi8dsOJ3m2tW2HW/ziSGtGsNYwCb7aR9enZDjsnOsWIdpo23rj4dwywXYB3YWV9olsHyp7Lbfp0E4zoRdpGc7r/BbjxgRYcF+5g9Hnr22B+tntdsjcHfEEOcrQA63vZbacDKrn3EEIzeZKCQV1LMsvbaqEMEVBUzKqdDawBkNrFGUefmjMz/iiq9ZKYXqFeolQWgFFuBcW/YqHiL07mg0boAGC2p0Fk3FBTLXbKxDsdRrFjD8rE2SSwb2SK463PgzRz07HxhEhYLU7Kzk2k2orriMF6vyiuY5SUsQzLee8yad5WVEuD+neOErfGO9W3YUx34yBvOZhV5ZV3s/UbjPtlZxEDreN79xU46XbPTT5MPsLO7p3tT2Fma6Ev7RCDUAxkzl/CVU22duWy0W1Aoj1Ncv53qUAyNNRZTdyyDs6ZYe9RfGjtH6zMWD1D2x1DEq0W5Lb++T9F2MVboRdB9LmBWFatQeY86WHneCGI1Sy1L+xsWGSFQeU9ETyYbWxE0u36AbXv9E9iqR5xkorIOfrs6Vmz4fyjJ0M22fUSzaoF2DQjaBkNbjdZeM0oBKFcU7RmtqmFhyxTdWZKXxBHrYNvbz2SdXNKJpVl2wZavH8bmfuK3vrB3L4mVffkD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Task " = _t, #"Start Time " = _t, #"End Time " = _t, #"Duration " = _t, #"Start Day" = _t]),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
#"Changed Type" = Table.TransformColumnTypes(#"Added Index",{{"Task ", type text}, {"Start Time ", type time}, {"End Time ", type time}, {"Duration ", type time}, {"Start Day", type text}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each [#"End Time "] - [#"Start Time "], type duration),
#"Added Custom" = Table.AddColumn(#"Inserted Time Subtraction", "Custom", each let x = Duration.TotalMinutes([Subtraction]),
y = if x<0 then x*-1 else x in y),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Times([#"Start Time "],[Custom],#duration(0,0,1,0))),
#"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"Custom.1", type time}}),
#"Inserted Hour" = Table.AddColumn(#"Changed Type1", "Hour", each Time.Hour([Custom.1]), Int64.Type),
#"Grouped Rows" = Table.Group(#"Inserted Hour", {"Index", "Hour"}, {{"min", each List.Min([Custom.1]), type nullable time}, {"max", each List.Max([Custom.1]), type nullable time}}),
#"Added Custom2" = Table.AddColumn(#"Grouped Rows", "Custom", each Duration.TotalMinutes([max] - [min])+1),
#"Merged Queries" = Table.NestedJoin(#"Added Index", {"Index"}, #"Added Custom2", {"Index"}, "Added Custom2", JoinKind.LeftOuter),
#"Expanded Added Custom2" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom2", {"Hour", "Custom"}, {"Hour", "Custom"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded Added Custom2",{"Task ", "Hour", "Custom", "Start Day"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Custom", "MinsInHours"}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"MinsInHours", Int64.Type}})
in
#"Changed Type2"
Edit
The same code will work with whatever row gets added
From here
To
In Power BI, I have a table looks like:
Customer; Amount Paid; Pay CCY; Amount Received; Received CCY
A 10 USD -20 GBP
B 50 CAD -30 USD
C 100 GBP -50 CAD
I'd like to convert table to:
Customer Amount CCY
A 10 USD
B 50 CAD
C 100 GBP
A -20 GBP
B -30 USD
C -50 CAD
Is there an easy way?
In the Query Editor, select the amount columns and click Unpivot Columns under the Transform tab.
The result should look like this:
Then you can define a custom column to pick which current to use either based on the Attribute column or the Value column. Then remove the extra columns.
The whole query (pasted from the Advanced Editor) looks something like this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0ABKhwS5AUtcIxHZ3ClCK1YlWcgKyTUECzo5gSWOYQpCkM1gnTDlQFq4yNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, #"Amount Paid" = _t, #"Pay CCY" = _t, #"Amount Received" = _t, #"Recieved CCY" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Amount Paid", Int64.Type}, {"Pay CCY", type text}, {"Amount Received", Int64.Type}, {"Recieved CCY", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Customer", "Pay CCY", "Recieved CCY"}, "Attribute", "Amount"),
#"Sorted Rows" = Table.Sort(#"Unpivoted Columns",{{"Attribute", Order.Ascending}, {"Customer", Order.Ascending}}),
#"Added Custom" = Table.AddColumn(#"Sorted Rows", "CCY", each if [Amount] > 0 then [Pay CCY] else [Recieved CCY], type text),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Pay CCY", "Recieved CCY", "Attribute"})
in
#"Removed Columns"
As said in the comment one could just append the tables. I started with this example
I just appended the table to itself, here is the M -Code
let
Source = Excel.CurrentWorkbook(){[Name="tblData"]}[Content],
tblStart1 = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Amount Paid", Int64.Type}, {"Pay CCY", type text}, {"Amount Received", Int64.Type}, {"Received CCY", type text}}),
removeColumns1 = Table.SelectColumns(tblStart1,{"Customer", "Amount Paid", "Pay CCY"}),
tblLeft = Table.RenameColumns(removeColumns1,{{"Amount Paid", "Amount"}, {"Pay CCY", "CCY"}}),
tblStart2 = tblStart1,
removeColumns = Table.SelectColumns(tblStart2,{"Customer", "Amount Received", "Received CCY"}),
tblRight = Table.RenameColumns(removeColumns,{{"Amount Received", "Amount"}, {"Received CCY", "CCY"}}),
tblCombine = Table.Combine({tblLeft,tblRight})
in
tblCombine
Result is
i am trying to get quarter from date ..
i tried this query
let
Source = "",
Custom1 = Source,
Custom2 = Calendar2,
Custom3 = let
Source = List.Dates(#date(1996, 1, 1), 500, #duration(1, 0, 0, 0)),#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),StartDate = #date(2016, 1, 1),
Today = DateTime.Date(DateTime.LocalNow()),
Length = Duration.Days(Today - StartDate),
Custom1 = #"Changed Type",
#"Inserted Year" = Table.AddColumn(Custom1, "Fin Year", each Date.Year([Date]+#duration(184,0,0,0)), Int64.Type),
#"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Date]), type text),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Month Name", "Day Name", each Date.DayOfWeekName([Date]), type text),
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Quarter of Year","Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type),
#"Inserted Month" = Table.AddColumn(#"Inserted Day Name", "Fin Month", each if Date.Month([Date]) >=7 then Date.Month([Date])-6 else Date.Month([Date])+6 , Int64.Type),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Month", "Day of Week", each Date.DayOfWeek([Date])+1, Int64.Type),
#"Inserted First Characters" = Table.AddColumn(#"Inserted Day of Week", "MMM", each Text.Start([Month Name], 3), type text),
#"Inserted First Characters1" = Table.AddColumn(#"Inserted First Characters", "DDD", each Text.Start([Day Name], 3), type text),
#"Reordered Columns" = Table.ReorderColumns(#"Inserted First Characters1",{"Date", "Fin Year", "Month Name", "MMM", "Fin Month", "Day Name", "DDD", "Day of Week"}),
#"Added Custom" = Table.AddColumn(#"Reordered Columns", "YYMM", each ([Fin Year]-2000)*100 + [Fin Month]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"YYMM", Int64.Type}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "MonthID", each (Date.Year([Date]) - Date.Year(StartDate))*12 + Date.Month([Date])),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"MonthID", Int64.Type}})
in
#"Changed Type2"
in
Custom3
quarter line from above code
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Quarter of Year","Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type),
when i tried this shows an error
Expression.Error: The name 'Inserted Quarter of Year' wasn't recognized. Make sure it's spelled correctly.
and also there is probelm when i rename "Fin Month " to only "Month" this shows also an error
how to resolve this
You have the syntax wrong and self referring to the column that you are trying to create, you need to reference the previous step.
Inserted Quarter of Year
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Quarter of Year","Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type),
should be:
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Day Name", "Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type)
Hope that helps