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
mathew_528417
Frequent Visitor

Summarize within Dates Between

Hey you all, I hope you all are ok!

I have the following (imaginary) database to work on:

mathew_528417_0-1663607378297.png

 

What I need to achieve is below:

mathew_528417_2-1663607505093.png


In other words, I need to multiplicate each demand due to its opening e closing date, considering the end of month of between those dates. But, the "AGE_DATE" can not be grater then the closing date. Also, if the demand does not has a closing date, the "AGE_DATE" must be the last day of refresh database.

 

Hope you can help me.

 

Thanks a lot. Regards from Brasil.

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @mathew_528417 ,


Here a solution in Power Query.

 

Before:

tomfox_1-1663611679174.png

 

 

After:

tomfox_0-1663611662409.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcrLCQAgDATRXvZsIFn/tYT034aiIB7nMe4wZiRQSdEsOl50MUMkR6ntQ3LH8T7mddunKN90ImIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Demand = _t, OPENING_DATE = _t, CLOSING_DATE = _t]),
    #"Changed Type 1" = Table.TransformColumnTypes(Source,{{"Demand", Int64.Type}, {"OPENING_DATE", type date}, {"CLOSING_DATE", type date}}),
    #"Added Custom 1" = Table.AddColumn(#"Changed Type 1", "AGE_DATE", each { Number.From ( [OPENING_DATE] ) .. Number.From ( if [CLOSING_DATE] = null then Date.From(DateTime.LocalNow())
 else [CLOSING_DATE] )  }),
    #"Expanded AGE_DATE" = Table.ExpandListColumn(#"Added Custom 1", "AGE_DATE"),
    #"Changed Type 2" = Table.TransformColumnTypes(#"Expanded AGE_DATE",{{"AGE_DATE", type date}}),
    #"Added Custom 2" = Table.AddColumn(#"Changed Type 2", "END_OF_MONTH", each Date.EndOfMonth([AGE_DATE])),
    #"Added Custom 3" = Table.AddColumn(#"Added Custom 2", "FILTER", each if [AGE_DATE] = [END_OF_MONTH] or [AGE_DATE] = Date.From(DateTime.LocalNow()) or [AGE_DATE] = [CLOSING_DATE] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom 3", each ([FILTER] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"END_OF_MONTH", "FILTER"})
in
    #"Removed Columns"

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
tackytechtom
Super User
Super User

Hi @mathew_528417 ,


Here a solution in Power Query.

 

Before:

tomfox_1-1663611679174.png

 

 

After:

tomfox_0-1663611662409.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcrLCQAgDATRXvZsIFn/tYT034aiIB7nMe4wZiRQSdEsOl50MUMkR6ntQ3LH8T7mddunKN90ImIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Demand = _t, OPENING_DATE = _t, CLOSING_DATE = _t]),
    #"Changed Type 1" = Table.TransformColumnTypes(Source,{{"Demand", Int64.Type}, {"OPENING_DATE", type date}, {"CLOSING_DATE", type date}}),
    #"Added Custom 1" = Table.AddColumn(#"Changed Type 1", "AGE_DATE", each { Number.From ( [OPENING_DATE] ) .. Number.From ( if [CLOSING_DATE] = null then Date.From(DateTime.LocalNow())
 else [CLOSING_DATE] )  }),
    #"Expanded AGE_DATE" = Table.ExpandListColumn(#"Added Custom 1", "AGE_DATE"),
    #"Changed Type 2" = Table.TransformColumnTypes(#"Expanded AGE_DATE",{{"AGE_DATE", type date}}),
    #"Added Custom 2" = Table.AddColumn(#"Changed Type 2", "END_OF_MONTH", each Date.EndOfMonth([AGE_DATE])),
    #"Added Custom 3" = Table.AddColumn(#"Added Custom 2", "FILTER", each if [AGE_DATE] = [END_OF_MONTH] or [AGE_DATE] = Date.From(DateTime.LocalNow()) or [AGE_DATE] = [CLOSING_DATE] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom 3", each ([FILTER] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"END_OF_MONTH", "FILTER"})
in
    #"Removed Columns"

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Hey @tackytechtom , thanks a lot, man!

 

It worked better than I thought! 

 

Regards!

tamerj1
Super User
Super User

@mathew_528417 

Please refer to attached sample file

1.png2.png

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.