Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Split multiple years date column to multiple lines graph it

Hello,

 

I am a fresh new user and want, from a data set with a column timestamp with multiple years (2015, 2014, 2013...), to produce a graph to compare events between the years.

 

Any idea on how to do it ?

Please ask if i am not clear

 

Thank you

 

  • Hi Anonymous 

    If your [TS col] column can be transformed to "date" type and format as below without any error,

    If not, please spilt your [TS col] column as amitchandak  suggested, or you could split it in power query like the following:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XcrJCQAgDATAXvYtmMS7Fkn/bWhQIfgcmDkhJBRZEFCg4Zm3szNtj2se51dn/8325bl/v5/fnO0nqC4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"TS col" = _t, Values = _t]),
        #"Split Column by Delimiter" = Table.SplitColumn(Source, "TS col", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"TS col.1", "TS col.2"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"TS col.1", Int64.Type}, {"TS col.2", Int64.Type}, {"Values", Int64.Type}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"TS col.1", "year"}, {"TS col.2", "month"}}),
        #"Inserted Merged Column" = Table.AddColumn(#"Renamed Columns", "date format", each Text.Combine({Text.Combine({Text.From([year], "en-US"), Text.From([month], "en-US")}, "/"),Text.From(1,"en-US")},"/"), type text),
        #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Merged Column",{{"date format", type date}})
    in
        #"Changed Type1"

    Then close&&apply, create a date table, add columns to visuals as below

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

6 Replies

  • Can you explain with an example

    Timestamp can be converted into date like

     

    Date = table[timestamp].date

    Year- format(table[timestamp],"YYYY")

    Month Year = format(table[timestamp].date,"MMM-YYYY")

    Month Year sort= format(table[timestamp].date,"YYYYMM")

    Appreciate your Kudos.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for your answers !

      Here is an example :

      TS colValues
      2020/125
      2020/114
      2020/109
      ......
      2019/126
      2019/114
      2019/102
      ......
      2018/126
      2018/117
      2018/103

       

      I want to print a graph to compare values with a line for each year.

       

      Regards

       

       

      • amitchandak's avatar
        amitchandak
        Super User

        Prefer to convert it into date

        date = Date(left([TS col],4),right([TS col],2),1)

        and use time intelligence using date. Totalytd, datesytd etc

        YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
        This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))
        
        Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
        Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
        Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
        Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
        

        To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
        https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
        https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
        https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

         

        Appreciate your Kudos.