Forum Discussion

noob123newbie's avatar
noob123newbie
Frequent Visitor
2 years ago
Solved

Custom Column on YYYYMM

Hi team,   I am new to PowerBI and working my way to figuring out the intricate functions in BI.  I have a SQL database linked to my Dashboard, and i actually need an additional column to be added...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi noob123newbie ,

     

    Open "Advanced Editor" and copy and paste the following code. You can check the steps on the right side.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc65DcAgEAXRXogd7P7lrAXRfxvIssyQPU00cyaZ3EZaz0c36FA/ZQ6vGjDDAitssMPzIB7Eg3gIHsKuGjDDAitssMPzEDzE+7A2", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ClosedAt = _t]),
        #"Split Column by Position" = Table.SplitColumn(Source, "ClosedAt", Splitter.SplitTextByPositions({0, 4}, false), {"ClosedAt.1", "ClosedAt.2"}),
        #"Added Custom" = Table.AddColumn(#"Split Column by Position", "Custom", each Date.FromText([ClosedAt.1]&"/"&[ClosedAt.2]&"/"&"1")),
        #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}}),
        #"Added Custom1" = Table.AddColumn(#"Changed Type", "Custom.1", each if Date.Month([Custom])>=10 then "FY"&Text.From(Value.FromText([ClosedAt.1])+1) else if Date.Month([Custom])>=1 and  Date.Month([Custom])<10 then "FY"&[ClosedAt.1] else null),
        #"Merged Columns" = Table.CombineColumns(#"Added Custom1",{"ClosedAt.1", "ClosedAt.2"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged"),
        #"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Custom"}),
        #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Merged", "ClosedAt"}, {"Custom.1", "CustomFY"}})
    in
        #"Renamed Columns"

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.