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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ahmed_hm
Regular Visitor

Repeat the same value for whole month

Hi there, 

 

I have a table containing the first date of each month and the budget for that day, this VALUE will be fixed daily, now I need to create a new table in Power BI to repeat this value for the whole month, any idea on how to achieve that? 

 appreciate your cooperation.

 

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJS0lGyMLNQitWJVjJCCBkaGYOFjBFClhBFJsiKTMBCpgghE1MzpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Budget = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Budget", Int64.Type}}),
    #"Added Custom" = Table.ReplaceValue(#"Changed Type",each [Date], each List.Dates([Date],Date.DaysInMonth([Date]),#duration(1,0,0,0)),Replacer.ReplaceValue,{"Date"}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date")
in
    #"Expanded Date"

 

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @ahmed_hm ,

 

You may follow @Vijay_A_Verma 's method which is efficient.

 

My workaround is firstly getting the EndDate of each month and then converting dates to number type and use {fFirstDate..EndDate} to get full dates, You could create a new blank query and then paste the following M in Advanced Editor dialog:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc7JCQAxDEPRXnwOxHb2WoL7b2OUIaBcBE+nv7e4umeTJCaRLh10soCFrGAlG9jIDnZygIOc4CQXuEjT06HP8Yc9ZXbSMBEf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"First Date" = _t, Budget = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"First Date", type date}, {"Budget", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Full Date", each { Number.From([First Date])..Number.From( Date.EndOfMonth([First Date]))}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Full Date"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Full Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"First Date"})
in
    #"Removed Columns"

 

Eyelyn9_0-1653618233654.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJS0lGyMLNQitWJVjJCCBkaGYOFjBFClhBFJsiKTMBCpgghE1MzpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Budget = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Budget", Int64.Type}}),
    #"Added Custom" = Table.ReplaceValue(#"Changed Type",each [Date], each List.Dates([Date],Date.DaysInMonth([Date]),#duration(1,0,0,0)),Replacer.ReplaceValue,{"Date"}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date")
in
    #"Expanded Date"

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors