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
KGPBI
Regular Visitor

Count difference between dates

I would like to count the number of days an invoice is paid in full. So in the same column the difference between the min and max date per invoice number.

As a table I use the general ledger mutation table for this. So I have multiple rows per invoice. This looks like this:
Invoice numberdate
1011-1-2019
1011-2-2019
1012-2-2019
1013-2-2019
1014-2-2019
1015-2-2019
1016-2-2019
1017-2-2019
1021-1-2019
1022-1-2019
1023-1-2019
1024-1-2019

 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

@KGPBI , a most straightforward way is to calculate the duration in Power Query,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc7BDQAQEATAXu5NYtchahH9tyHxIOx3XjOGIcGCISIyodsMl/gTlbKSKxWlqtReor64E0JZyQ/NBQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Invoice number" = _t, date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice number", Int64.Type}, {"date", type date}}, "en-GB"),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"Invoice number"}, {{"Diff", each Duration.Days(List.Max([date])-List.Min([date]))+1}})
in
    #"Grouped Rows"

Screenshot 2021-02-25 151931.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
KGPBI
Regular Visitor

@CNENFRNL thanks i should learn more Power query!

CNENFRNL
Community Champion
Community Champion

@KGPBI , a most straightforward way is to calculate the duration in Power Query,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc7BDQAQEATAXu5NYtchahH9tyHxIOx3XjOGIcGCISIyodsMl/gTlbKSKxWlqtReor64E0JZyQ/NBQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Invoice number" = _t, date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice number", Int64.Type}, {"date", type date}}, "en-GB"),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"Invoice number"}, {{"Diff", each Duration.Days(List.Max([date])-List.Min([date]))+1}})
in
    #"Grouped Rows"

Screenshot 2021-02-25 151931.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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.