Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
upniwesh
Regular Visitor

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

 

1 ACCEPTED SOLUTION
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"

vstephenmsft_0-1686796531217.png

 

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

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

vstephenmsft_10-1686797079487.png

vstephenmsft_11-1686797088297.png

 

 

3.In Query1, click "Merge Queries".

vstephenmsft_2-1686796635597.png

Merge with the main table as follows.

vstephenmsft_14-1686797166556.png

vstephenmsft_5-1686796720303.png

 

4.Expand the custom column contains 1.

vstephenmsft_12-1686797135327.png

vstephenmsft_13-1686797144640.png

 

 

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

vstephenmsft_15-1686797192002.png

vstephenmsft_16-1686797219328.png

 

 

6.Group by MonthName and sum two columns.

vstephenmsft_17-1686797240685.pngvstephenmsft_18-1686797271383.png

vstephenmsft_19-1686797276143.png

                                                                                                                                                         

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.           

 

 

 

View solution in original post

4 REPLIES 4
slorin
Super User
Super User

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
slorin
Super User
Super User

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 

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
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"

vstephenmsft_0-1686796531217.png

 

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

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

vstephenmsft_10-1686797079487.png

vstephenmsft_11-1686797088297.png

 

 

3.In Query1, click "Merge Queries".

vstephenmsft_2-1686796635597.png

Merge with the main table as follows.

vstephenmsft_14-1686797166556.png

vstephenmsft_5-1686796720303.png

 

4.Expand the custom column contains 1.

vstephenmsft_12-1686797135327.png

vstephenmsft_13-1686797144640.png

 

 

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

vstephenmsft_15-1686797192002.png

vstephenmsft_16-1686797219328.png

 

 

6.Group by MonthName and sum two columns.

vstephenmsft_17-1686797240685.pngvstephenmsft_18-1686797271383.png

vstephenmsft_19-1686797276143.png

                                                                                                                                                         

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.           

 

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.