Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
Hi All,
Each section shows an invoice start date and end date.
Some may coincide with the same periods.
I wanna find the green empty section.
April and May 2020 are empty.
My purpose is how many months are empty between the first date and the last date of the customer with this ID number.
And how many months are filled between the first date and the last date?
For Exp below: Empty:2 Filled:70 Total: 72 and 70/72=%97
Many thanks.
Database table example.
Customer ID | Invoice No | Start Date | End Date |
1124 | 220001 | 1.01.2017 | 31.12.2017 |
1124 | 220002 | 1.01.2018 | 31.03.2018 |
1124 | 220003 | 1.01.2018 | 31.12.2018 |
1124 | 220004 | 1.03.2018 | 31.05.2018 |
1124 | 220005 | 1.06.2018 | 31.08.2018 |
1124 | 220006 | 1.07.2018 | 30.09.2018 |
1124 | 220007 | 1.08.2018 | 31.10.2018 |
1124 | 220008 | 1.09.2018 | 30.11.2018 |
1124 | 220009 | 1.12.2018 | 28.02.2019 |
1124 | 220010 | 1.12.2018 | 28.02.2019 |
1124 | 220011 | 1.01.2019 | 31.03.2019 |
1124 | 220012 | 1.01.2019 | 31.03.2019 |
1124 | 220013 | 1.01.2019 | 31.12.2019 |
1124 | 220014 | 1.03.2019 | 31.05.2019 |
1124 | 220015 | 1.03.2019 | 31.05.2019 |
1124 | 220016 | 1.04.2019 | 30.06.2019 |
1124 | 220017 | 1.04.2019 | 30.06.2019 |
1124 | 220018 | 1.04.2019 | 30.06.2019 |
1124 | 220019 | 1.05.2019 | 31.07.2019 |
1124 | 220020 | 1.07.2019 | 30.09.2019 |
1124 | 220021 | 1.07.2019 | 30.09.2019 |
1124 | 220022 | 1.07.2019 | 30.09.2019 |
1124 | 220023 | 1.07.2019 | 30.09.2019 |
1124 | 220024 | 1.10.2019 | 31.12.2019 |
1124 | 220025 | 1.10.2019 | 31.12.2019 |
1124 | 220026 | 1.10.2019 | 31.12.2019 |
1124 | 220027 | 1.10.2019 | 31.12.2019 |
1124 | 220028 | 1.11.2019 | 31.01.2020 |
1124 | 220029 | 1.01.2020 | 31.03.2020 |
1124 | 220030 | 1.01.2020 | 31.03.2020 |
1124 | 220031 | 1.06.2020 | 31.08.2020 |
1124 | 220032 | 1.06.2020 | 31.08.2020 |
1124 | 220033 | 1.07.2020 | 30.09.2020 |
1124 | 220034 | 1.08.2020 | 31.10.2020 |
1124 | 220035 | 1.09.2020 | 30.11.2020 |
1124 | 220036 | 1.09.2020 | 30.11.2020 |
1124 | 220037 | 1.09.2020 | 30.11.2020 |
1124 | 220038 | 1.10.2020 | 31.12.2020 |
1124 | 220039 | 1.12.2020 | 28.02.2021 |
1124 | 220040 | 1.12.2020 | 28.02.2021 |
1124 | 220041 | 1.01.2021 | 31.03.2021 |
1124 | 220042 | 1.01.2021 | 31.12.2021 |
1124 | 220043 | 1.02.2021 | 30.04.2021 |
1124 | 220044 | 1.04.2021 | 30.06.2021 |
1124 | 220045 | 1.04.2021 | 30.06.2021 |
1124 | 220046 | 1.04.2021 | 30.06.2021 |
1124 | 220047 | 1.05.2021 | 31.07.2021 |
1124 | 220048 | 1.05.2021 | 31.07.2021 |
1124 | 220049 | 1.07.2021 | 30.09.2021 |
1124 | 220050 | 1.07.2021 | 30.09.2021 |
1124 | 220051 | 1.07.2021 | 30.09.2021 |
1124 | 220052 | 1.09.2021 | 30.11.2021 |
1124 | 220053 | 1.09.2021 | 30.11.2021 |
1124 | 220054 | 1.10.2021 | 31.12.2021 |
1124 | 220055 | 1.10.2021 | 31.12.2021 |
1124 | 220056 | 1.10.2021 | 31.12.2021 |
1124 | 220057 | 1.10.2021 | 31.12.2021 |
1124 | 220058 | 1.11.2021 | 31.12.2021 |
1124 | 220059 | 1.01.2022 | 28.02.2022 |
1124 | 220060 | 1.01.2022 | 31.03.2022 |
1124 | 220061 | 1.01.2022 | 31.03.2022 |
1124 | 220062 | 1.01.2022 | 31.03.2022 |
1124 | 220063 | 1.01.2022 | 31.03.2022 |
1124 | 220064 | 1.03.2022 | 31.12.2022 |
Solved! Go to Solution.
Hi, @alikemalaydin
Try this:
M query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdZbjoMwDAXQvfBdIdt5r6Xq/rdRBpPEJe70/hF0ZIVcx+L53Jglbo9NhIj4eOCdeBficjwH3ll08Xp8UjG0KqWgizsNK9WqK41Kg62afJqUZkurT7PSMijt1HxalFa7V/JpVdpMVWaftpP2jz5e1p3ORbtTJpzatJqNYKWC07BS/rIBm1azaa004fRKKw5KV8orLTitONW0+vZ0r8WlQqazetXmU8ap4DTgVNPSbv4/WEk4zTgtONW0+KNf/xbHgd9pm/16xtFbe6WBcMpzugxafSo4NWkpvdJyaJyDqFc9T86haQ6iXpX9wwoZpwWndQY79io+NZPwpH28HdfjRiPh1EzC856NYFcqK+UvVa+0ZFDS+eHQOKfLoNmnCacZp2XOrHECxacVp830a99Ac2kinDJOxTQh2yZcacCpmYQ/eiAlnGacFpyaSfiL2kko9sLInWa60XFhVso4FZwGnJq/jE65f9brDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer ID" = _t, #"Invoice No" = _t, #"Start Date" = _t, #"End Date" = _t]),
#"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Start Date", type date}, {"End Date", type date}}, "en-GB"),
#"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Customer ID", Int64.Type}, {"Invoice No", Int64.Type}}),
startDate=List.Buffer(#"Changed Type"[Start Date]),
endDate=List.Buffer(#"Changed Type"[End Date]),
#"Added Custom1" = Table.AddColumn(#"Changed Type", "Range", each List.Transform({Number.From([Start Date])..Number.From([End Date])}, each Date.From(_))),
#"Merged Queries" = Table.NestedJoin(#"Added Custom1", {"Customer ID"}, #"Added Custom1", {"Customer ID"}, "MergeTable", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "AllRange", each List.Union([MergeTable][Range])),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Calendar", each List.Transform({Number.From(List.Min(startDate))..Number.From(List.Max(endDate))}, each Date.From(_))),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "EmptyDate", each List.RemoveMatchingItems([Calendar],[AllRange])),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Range", "MergeTable", "AllRange", "Calendar"}),
#"Added Custom4" = Table.AddColumn(#"Removed Columns", "Year-Month", each List.Distinct(List.Transform([EmptyDate], each Text.From(Date.Year(_))&"-"&Text.From(Date.Month(_))))),
#"Added Custom6" = Table.AddColumn(#"Added Custom4", "Count_EmptyDateMonth", each List.Count([#"Year-Month"])),
#"Added Custom5" = Table.AddColumn(#"Added Custom6", "yyyy-mm", each List.Accumulate([#"Year-Month"], "", (state, current) => state&", "¤t)),
#"Extracted Text After Delimiter" = Table.TransformColumns(#"Added Custom5", {{"yyyy-mm", each Text.AfterDelimiter(_, " "), type text}}),
#"Removed Columns1" = Table.RemoveColumns(#"Extracted Text After Delimiter",{"EmptyDate", "Year-Month"})
in
#"Removed Columns1"
Result:
Please refer to the attachment below for details.
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @alikemalaydin
Try this:
M query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdZbjoMwDAXQvfBdIdt5r6Xq/rdRBpPEJe70/hF0ZIVcx+L53Jglbo9NhIj4eOCdeBficjwH3ll08Xp8UjG0KqWgizsNK9WqK41Kg62afJqUZkurT7PSMijt1HxalFa7V/JpVdpMVWaftpP2jz5e1p3ORbtTJpzatJqNYKWC07BS/rIBm1azaa004fRKKw5KV8orLTitONW0+vZ0r8WlQqazetXmU8ap4DTgVNPSbv4/WEk4zTgtONW0+KNf/xbHgd9pm/16xtFbe6WBcMpzugxafSo4NWkpvdJyaJyDqFc9T86haQ6iXpX9wwoZpwWndQY79io+NZPwpH28HdfjRiPh1EzC856NYFcqK+UvVa+0ZFDS+eHQOKfLoNmnCacZp2XOrHECxacVp830a99Ac2kinDJOxTQh2yZcacCpmYQ/eiAlnGacFpyaSfiL2kko9sLInWa60XFhVso4FZwGnJq/jE65f9brDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer ID" = _t, #"Invoice No" = _t, #"Start Date" = _t, #"End Date" = _t]),
#"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Start Date", type date}, {"End Date", type date}}, "en-GB"),
#"Changed Type" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"Customer ID", Int64.Type}, {"Invoice No", Int64.Type}}),
startDate=List.Buffer(#"Changed Type"[Start Date]),
endDate=List.Buffer(#"Changed Type"[End Date]),
#"Added Custom1" = Table.AddColumn(#"Changed Type", "Range", each List.Transform({Number.From([Start Date])..Number.From([End Date])}, each Date.From(_))),
#"Merged Queries" = Table.NestedJoin(#"Added Custom1", {"Customer ID"}, #"Added Custom1", {"Customer ID"}, "MergeTable", JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "AllRange", each List.Union([MergeTable][Range])),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Calendar", each List.Transform({Number.From(List.Min(startDate))..Number.From(List.Max(endDate))}, each Date.From(_))),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "EmptyDate", each List.RemoveMatchingItems([Calendar],[AllRange])),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Range", "MergeTable", "AllRange", "Calendar"}),
#"Added Custom4" = Table.AddColumn(#"Removed Columns", "Year-Month", each List.Distinct(List.Transform([EmptyDate], each Text.From(Date.Year(_))&"-"&Text.From(Date.Month(_))))),
#"Added Custom6" = Table.AddColumn(#"Added Custom4", "Count_EmptyDateMonth", each List.Count([#"Year-Month"])),
#"Added Custom5" = Table.AddColumn(#"Added Custom6", "yyyy-mm", each List.Accumulate([#"Year-Month"], "", (state, current) => state&", "¤t)),
#"Extracted Text After Delimiter" = Table.TransformColumns(#"Added Custom5", {{"yyyy-mm", each Text.AfterDelimiter(_, " "), type text}}),
#"Removed Columns1" = Table.RemoveColumns(#"Extracted Text After Delimiter",{"EmptyDate", "Year-Month"})
in
#"Removed Columns1"
Result:
Please refer to the attachment below for details.
Hope this helps.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Thanks for your solution.
I adapted the solution to my tables and controlled the numbers.
My new problem is someone invoices do not start the first month of the year or end the last month of the year.
Exp below: The red ones are overcalculated.
Hi, @alikemalaydin
Based on the information you provided, finding the missing dates is based on all the invoice dates for a user. In my solution, the [yyyy-mm] column is also based on all the invoice dates for a user.
If it is not based on all dates, you cannot get the missing dates for a single invoice.
You don't need to care about the [yyyy-mm] column value for a user's single invoice in power query, you just need to get the results for the card measures.
Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Many thanks for your help.