Forum Discussion
Display line graph for two data from one table
- Anonymous3 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.
Source :
| Task Name | Target Date | Alert Date |
| Task 1 | 13/06/2023 | 13/09/2023 |
| Task 2 | 05/05/2023 | 10/08/2023 |
| Task 3 | 10/05/2023 | 10/07/2023 |
If someone can help to get data by Power BI Query in the below format from the above table?
Required:
| Month | Alert Count | TargetCount |
| Jan | 0 | 0 |
| Feb | 0 | 0 |
| March | 0 | 0 |
| April | 0 | 0 |
| May | 0 | 2 |
| June | 0 | 1 |
| July | 1 | 0 |
| Aug | 1 | 0 |
| Sep | 1 | 0 |
| Oct | 0 | 0 |
| Nov | 0 | 0 |
| Dec | 0 | 0 |
--
Thanks
Upniwesh
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.