Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi All,
I have a Table - RatePlan and 2 specifc Columns I'm focusing on:
UNIQLIN (Id from another table)
INSERTDATE (date)
The field UNIQLIN appears multiple times but with different dates in INSERTDATE.
At the Query level, I would like to add a "CURRENT_RECORD" Y/N field.
so it would like this
Solved! Go to Solution.
Hello @marktvc
you can add a Group-function on your ID with 2 function. AllRows and MaxDate of your date-column.
After that expand your grouped table and check whether your date-column is the same as the MaxDate.
Here some code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1TMw0jMyUIrVgQgYG+gZGCMLGBnoGcJVOAEFDC3QBYAqDMACsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UNIQLIN = _t, INSERTDATE = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"UNIQLIN", type text}, {"INSERTDATE", type date}}, "de-DE"),
#"Grouped Rows" = Table.Group(#"Changed Type", {"UNIQLIN"}, {{"MaxDate", each List.Max([INSERTDATE]), type date}, {"AllRows", each _, type table [UNIQLIN=text, INSERTDATE=date]}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"INSERTDATE"}, {"INSERTDATE"}),
#"Added Custom" = Table.AddColumn(#"Expanded AllRows", "CURRENT_RECORD", each if [MaxDate]=[INSERTDATE] then "Y" else "N"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MaxDate"})
in
#"Removed Columns"
transforms this
into this
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hello @marktvc
you can add a Group-function on your ID with 2 function. AllRows and MaxDate of your date-column.
After that expand your grouped table and check whether your date-column is the same as the MaxDate.
Here some code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1TMw0jMyUIrVgQgYG+gZGCMLGBnoGcJVOAEFDC3QBYAqDMACsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UNIQLIN = _t, INSERTDATE = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"UNIQLIN", type text}, {"INSERTDATE", type date}}, "de-DE"),
#"Grouped Rows" = Table.Group(#"Changed Type", {"UNIQLIN"}, {{"MaxDate", each List.Max([INSERTDATE]), type date}, {"AllRows", each _, type table [UNIQLIN=text, INSERTDATE=date]}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"INSERTDATE"}, {"INSERTDATE"}),
#"Added Custom" = Table.AddColumn(#"Expanded AllRows", "CURRENT_RECORD", each if [MaxDate]=[INSERTDATE] then "Y" else "N"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MaxDate"})
in
#"Removed Columns"
transforms this
into this
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
here is my revise code. it isn't quite perfecet as it generates a duplicate to UniqLine (UniqLine.1).
Thanks Jimmy for pointing me in the right direction.
#"Grouped Rows" = Table.Group(dbo_CFRatePlan, {"UniqLine"}, {{"MaxDate", each List.Max([InsertedDate]), type date}, {"AllRows", each _, type table [UniqLine=text, InsertedDate=date, UniqCFRatePlan=text]}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"UniqLine", "InsertedDate", "UniqCFRatePlan"}, {"UniqLine.1", "InsertedDate", "UniqCFRatePlan"}),
#"Added Custom" = Table.AddColumn(#"Expanded AllRows", "CURRENT_RECORD", each if [MaxDate]=[InsertedDate] then "Y" else "N"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MaxDate"}),
#"Removed Columns1" = Table.RemoveColumns(#"Removed Columns",{"UniqLine.1"})
in
#"Removed Columns1"
I'm getting this error on the reload of data
let
Source = CFRatePlan,
#"Detected Type Mismatches" = let
tableWithOnlyPrimitiveTypes = Table.SelectColumns(Source, Table.ColumnsOfType(Source, {type nullable number, type nullable text, type nullable logical, type nullable date, type nullable datetime, type nullable datetimezone, type nullable time, type nullable duration})),
recordTypeFields = Type.RecordFields(Type.TableRow(Value.Type(tableWithOnlyPrimitiveTypes))),
fieldNames = Record.FieldNames(recordTypeFields),
fieldTypes = List.Transform(Record.ToList(recordTypeFields), each [Type]),
pairs = List.Transform(List.Positions(fieldNames), (i) => {fieldNames{i}, (v) => if v = null or Value.Is(v, fieldTypes{i}) then v else error [Message = "The type of the value does not match the type of the column.", Detail = v], fieldTypes{i}})
in
Table.TransformColumns(Source, pairs),
#"Added Index" = Table.AddIndexColumn(#"Detected Type Mismatches", "Row Number" ,1),
#"Kept Errors" = Table.SelectRowsWithErrors(#"Added Index", {"UniqLine", "InsertedDate", "UniqCFRatePlan", "CURRENT_RECORD"}),
#"Reordered Columns" = Table.ReorderColumns(#"Kept Errors", {"Row Number", "UniqLine", "InsertedDate", "UniqCFRatePlan", "CURRENT_RECORD"})
in
#"Reordered Columns"
Hello @marktvc
the group-step itself doesn't make your data disappear. It has to function that contains complete grouped table and the MaxDate. So you have to change the Expand-column step, where you have to define the columns you want again to see. Just check out the step on the right side, you can change this step in the GUI.
Hope it helps
BR
Jimmy
Almost there, I have a number of other columns which disappear in the "Group" step. I would like to see these.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
14 | |
13 | |
12 | |
12 | |
12 |