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

Previous month data add on 1st day of current month

Hi All, hope you can help with this issue i am having - 

 

I have created a "Period Table" within PowerBi that holds the date values as shown on below code:

 

let
TodaysDate = Date.From(DateTimeZone.FixedUtcNow()),
Ranges = {
{"Today",
TodaysDate,
TodaysDate,
1},
{"Current Week To Date",
Date.From(Date.StartOfWeek(TodaysDate)),
TodaysDate,
2},
{"Last 10 days",
Date.AddDays(TodaysDate,-10) + #duration(1,0,0,0),
TodaysDate,
3},
{"Current Month To Date",
Date.From(Date.StartOfMonth(TodaysDate)),
TodaysDate,
4},
{"Current Year To Date",
Date.From(Date.StartOfYear(TodaysDate)),
TodaysDate,
5},
{"Rolling Week",
Date.AddWeeks(TodaysDate,-1) + #duration(1,0,0,0),
TodaysDate,
6},
{"Rolling Month",
Date.AddMonths(TodaysDate,-1) + #duration(1,0,0,0),
TodaysDate,
7},
{"Last Month",
Date.AddMonths(Date.From(Date.StartOfMonth(TodaysDate)),-1),Date.StartOfMonth(TodaysDate),
8}
},
GetTables = List.Transform(Ranges,
each CreatePeriodTable(_{0}, _{1}, _{2}, _{3})),
Output = Table.Combine(GetTables)

in
Output

 

I have some problems with the "Last Month" section - i want to show all previous month data but it adds on the 1st day of the current month

 

Capture.JPG

 

Please can you advise what im doing wrong on the code:

 

{"Last Month",
Date.AddMonths(Date.From(Date.StartOfMonth(TodaysDate)),-1),Date.StartOfMonth(TodaysDate),
8}

 

Thank You

3 REPLIES 3
v-huizhn-msft
Employee
Employee

Hi @v7haquh,

For your issue, I recommand that you post it to Power Query forum. Other partners will read the forums regularly can either share their knowledge or learn from your interaction with us. So you will get the most qualified pool of respondents. Thank you for your understanding.

Best Regards,
Angelia

Many Thanks Angelia, i have done this 

Hi @v7haquh,

Ok, got it.

Best Regards,
Angelia

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.