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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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