Forum Discussion
chinthada
Helper I
6 years agoCreate new quarterly record with previous quarter data with conditions
Hello guys, I have a data table like below. When I apply a filter (Grade1) for "Class", for the year 2019, it only has 3 quarters (q1, q2, q3). I want to create a record for q4 with the value of ...
- 6 years ago
Hello
Please try this in the Query Editor:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci9KTEk1VNJRMjIwtARSgaWJRSWpRQrGQLaJgYmhUqwObkVGYEXGlngVGUIUWYAVOScWpxphN8jI0ACfEojJpviUmICEjICmxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Class = _t, Fiscal_Year = _t, Fiscal_Quarter = _t, Q_RunTot_Conn = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Class", type text}, {"Fiscal_Year", Int64.Type}, {"Fiscal_Quarter", type text}, {"Q_RunTot_Conn", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Class", "Fiscal_Year"}, {{"Data", each _, type table [Class=text, Fiscal_Year=number, Fiscal_Quarter=text, Q_RunTot_Conn=number]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let t = Table.AddColumn([Data],"Quarter",each Text.Replace([Fiscal_Quarter],"Quarter ","")) in Table.AddColumn(Table.ExpandListColumn( Table.AddColumn(t,"LastQ",each if [Quarter]<>"4" then List.Select({ Int64.From([Quarter]), let temp = Int64.From([Quarter])+1 in if Table.RowCount(Table.SelectRows(t,each Int64.From([Quarter]) = temp))=0 then Int64.From([Quarter])+1 else null },each _<>null) else {Int64.From([Quarter])} ), "LastQ"),"New Quarter",each "Quarter "&Text.From([LastQ]))), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Data"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Q_RunTot_Conn", "New Quarter"}, {"Q_RunTot_Conn", "Fiscal_Quarter"}) in #"Expanded Custom"The output shows:
Here is my test pbix file:
I hope this helps.
Best regards
Giotto Zhi
Greg_Deckler
Community Champion
6 years agoIn general you cannot "invent" columns using DAX. The exception is when you create an entirely new table using DAX. First question, are you trying to do this in Power Query or DAX? Second, data as text. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490. You could almost certainly do this creating a new table but you cannot invent a row using just custom columns.
- chinthada6 years ago
Helper I
Greg_Deckler Thanks for the reply. Wouldn't mind if we can get above output using Power Query.