Forum Discussion

upniwesh's avatar
upniwesh
Regular Visitor
3 years ago
Solved

Display line graph for two data from one table

I have one Excel sheet from where I am preparing the Dashboard.

I have data like below 

Task NameTarget DateAlert Date
Task 113/06/202313/09/2023
Task 205/05/202310/08/2023
Task 310/05/202310/07/2023

 

Now I need to prepare a line chart month wise which should have two series one for Targetdate Count and another for Alert Date Count. We need to get in which month how many alerts are there and how many targets are there.

e.g. As per above table 

May Target - 2, Alert 0

JuneTarget 1, Alert 0

July Target 0, Alert 1

Aug Target 0, Alert 1

Sep Target 0, Alert 1

Oct Target 0, Alert 0

 

Thanks for the help.

Upniwesh

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi upniwesh ,

     

    Here's my solution in Power Query. 

    1.Create a calendar table and extract months.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY11DVUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t]),
        #"Added Custom" = Table.AddColumn(Source, "EndDate", each Date.From("2023-12-31")),
        #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom",{{"EndDate", type date}}),
        #"Changed Type" = Table.TransformColumnTypes(#"Changed Type2",{{"StartDate", type date}}),
        #"Added Custom1" = Table.AddColumn(#"Changed Type", "Dates", each {Number.From([StartDate])..Number.From([EndDate])}),
        #"Expanded Dates" = Table.ExpandListColumn(#"Added Custom1", "Dates"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}}),
        #"Removed Columns1" = Table.RemoveColumns(#"Changed Type1",{"StartDate", "EndDate"}),
        #"Added Custom4" = Table.AddColumn(#"Removed Columns1", "MonthName", each Date.MonthName([Dates])),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom4",{"Dates"}),
        #"Removed Duplicates" = Table.Distinct(#"Removed Columns")
    in
        #"Removed Duplicates"

     

    2.Create two month name column and a custom column contains 1 in the main table.

    =Date.MonthName([Target Date])
    =Date.MonthName([Alert Date])

     

     

    3.In Query1, click "Merge Queries".

    Merge with the main table as follows.

     

    4.Expand the custom column contains 1.

     

     

    5.Merge again, replacing the matching column with Alert Month. After the merger is complete, expand the Alert Month column.

     

     

    6.Group by MonthName and sum two columns.

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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

     

     

     

4 Replies

  • upniwesh's avatar
    upniwesh
    Regular Visitor

    Source : 

    Task NameTarget DateAlert Date
    Task 113/06/202313/09/2023
    Task 205/05/202310/08/2023
    Task 310/05/202310/07/2023

     

    If someone can help to get data by Power BI Query in the below format from the above table?

    Required: 

    Month       Alert CountTargetCount
    Jan00
    Feb00
    March00
    April00
    May02
    June01
    July10
    Aug10
    Sep10
    Oct00
    Nov00
    Dec00

     

     

    --

    Thanks

    Upniwesh

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi upniwesh ,

       

      Here's my solution in Power Query. 

      1.Create a calendar table and extract months.

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY11DVUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t]),
          #"Added Custom" = Table.AddColumn(Source, "EndDate", each Date.From("2023-12-31")),
          #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom",{{"EndDate", type date}}),
          #"Changed Type" = Table.TransformColumnTypes(#"Changed Type2",{{"StartDate", type date}}),
          #"Added Custom1" = Table.AddColumn(#"Changed Type", "Dates", each {Number.From([StartDate])..Number.From([EndDate])}),
          #"Expanded Dates" = Table.ExpandListColumn(#"Added Custom1", "Dates"),
          #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}}),
          #"Removed Columns1" = Table.RemoveColumns(#"Changed Type1",{"StartDate", "EndDate"}),
          #"Added Custom4" = Table.AddColumn(#"Removed Columns1", "MonthName", each Date.MonthName([Dates])),
          #"Removed Columns" = Table.RemoveColumns(#"Added Custom4",{"Dates"}),
          #"Removed Duplicates" = Table.Distinct(#"Removed Columns")
      in
          #"Removed Duplicates"

       

      2.Create two month name column and a custom column contains 1 in the main table.

      =Date.MonthName([Target Date])
      =Date.MonthName([Alert Date])

       

       

      3.In Query1, click "Merge Queries".

      Merge with the main table as follows.

       

      4.Expand the custom column contains 1.

       

       

      5.Merge again, replacing the matching column with Alert Month. After the merger is complete, expand the Alert Month column.

       

       

      6.Group by MonthName and sum two columns.

                                                                                                                                                               

      Best Regards,

      Stephen Tao

       

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

       

       

       

  • Hi

     

    let
    Source = YourSource,
    UnPivot = Table.UnpivotOtherColumns(Source, {"Task Name"}, "Attribute", "Value"),
    StartOfMonth = Table.TransformColumns(UnPivot, {{"Value", each Date.StartOfMonth(_), type date}}),
    Pivot = Table.Pivot(StartOfMonth, List.Distinct(StartOfMonth[Attribute]), "Attribute", "Task Name", List.Count),
    List_Month = Table.FromColumns({List.Transform({1..12}, each Date.StartOfMonth(#date(2023,_,1)))},type table [Month= date]),
    Join = Table.NestedJoin(List_Month, {"Month"}, Pivot, {"Value"}, "Table", JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Join, "Table", {"Target Date", "Alert Date"}, {"Target Date", "Alert Date"}),
    Sort = Table.Sort(Expand,{{"Month", Order.Ascending}}),
    MonthName = Table.TransformColumns(Sort, {{"Month", each Date.MonthName(_), type text}})
    in
    MonthName

    Stéphane 

  • Hi, 

    Another solution without Table.Join

    let
    Source = YourSource,
    UnPivot = Table.UnpivotOtherColumns(Source, {"Task Name"}, "Attribute", "Month"),
    StartOfMonth = Table.TransformColumns(UnPivot, {{"Month", each Date.StartOfMonth(_), type date}}),
    Pivot = Table.Pivot(StartOfMonth, List.Distinct(StartOfMonth[Attribute]), "Attribute", "Task Name", List.Count),
    Combine = Table.Combine({Pivot,Table.FromColumns({List.Transform({1..12}, each Date.StartOfMonth(#date(2023,_,1)))},type table [Month= date])}),
    Distinct = Table.Distinct(Combine, {"Month"}),
    Sort = Table.Sort(Distinct,{{"Month", Order.Ascending}}),
    MonthName = Table.TransformColumns(Sort, {{"Month", each Date.MonthName(_), type text}})
    in
    MonthName