I need to create an dynamic list of months from current month back to 10 months ago using Power Query M. I found that there is only List.Dates to create a list of date between specific duration but no function help to create the months list.
Could anybody has some way to help?
Thanks
Not sure what you are looking for, but the following code will give you 3 columns for the previous 10 months and the current month (at last refresh, you need to refresh each month):
Start of Month (date)
End of Month (date)
Name of Month in Vietnamese (text)
let
Source = Table.FromList({-10..0}, each{_}),
AddedStartOfMonth = Table.AddColumn(Source, "StartOfMonth", each Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),[Column1])), type date),
AddedEndOfMonth = Table.AddColumn(AddedStartOfMonth, "EndOfMonth", each Date.EndOfMonth([StartOfMonth]), type date),
AddedNameOfMonthInVietnamese = Table.AddColumn(AddedEndOfMonth, "MonthName", each Date.MonthName([StartOfMonth],"vi-VN"), type text),
RemovedColumn = Table.RemoveColumns(AddedNameOfMonthInVietnamese,{"Column1"})
in
RemovedColumn
Assuming you want to achieve a filter, I would just hit the Filter drop-down button for your date column in the Query Editor, then choose Date/Time Filters / In the Previous / 10 / months. This will generate something like this:
Filtered Rows = Table.SelectRows(Source, each Date.IsInPreviousNMonths([My Date], 10))
Related
I am new to Power BI, having below date table
Created Week end date using below dax measure
Week End Date = 'Date'[Date] - WEEKDAY('Date'[Date],2) + 7
Can anyone advise the following?
How to sort the week end date? I created bar graph week end date vs Total hrs(which comes from other table) and it's working. However, axis week end data is not in proper order
How to format week end date into "MM/dd/YYYY" (Currently in "dd/MM/yyyy")
Sorry if this question is too basic. I tried various posts but no luck.
You cut your bar chart screenshot exactly on the ellipsis menu (...) in the upper right corner. This is usually the place to go and change the sort order of your x-axis. (Maybe your data doesn't allow this, but then you would need to post some sample data - no screenshot - as already requested above.)
To change the format to "MM/dd/YYYY" use
End of Week US = FORMAT('Table'[End Of Week], "MM/dd/yyyy")
I am very new to PowerBI and exploring it. I came across a sample data which has a start date and end date, Group Type and a Value. Basically its something like, an exam group has a start date and end date with a score.
I want to do a rollover calculation like when I view the dashboard it needs to provide me value for this month and for future months. The values needs to be added based on the start date and end date. For example, if the start date is 01-01-2020 and end date is 12-07-2020 and the score is 20 for one record and the start date is 02-03-2020 and end date is 31-05-2020 and the score is 09 for another record, the table needs to show something like for May 29, June, July - 20.
For current months the score must be added cumulatively and for the future months it has to show the cumulative score from that month to the remaining months excluding the current month.
Below is my expected output
Source Data is
It would be helpful for me if anyone can guide me what logic I need to use for this?
Source File
You can do this by adding an extra column where you sum all totals from earlier end dates:
rollover =
var lDate = Sheet1[End Date]
var place = Sheet1[Placement]
var total = CALCULATE(sum(Sheet1[Total]),filter(Sheet1, place = Sheet1[Placement] && lDate >= Sheet1[End Date]))
return total
result:
This you can bring into your visual..
I have a dashboard that needs to display the beginning of the week, on Monday, of the week that I'm in. So for example, if its 1/7/2020, this card would show 1/6/2020. Here is the code I was trying:
Report Date = CALCULATE(TODAY(), FILTER('Calendar', 'Calendar'[WeekStartDate]))
The column in the Calendar table is Weekstartdate, which is accurate and does show the week of 1/6/2020 with the corresponding dates to it; however, it looks like it won't filter it from today's date.
Any ideas? or advice on what I'm doing wrong?
If what you are looking for is a single date, which gives the week start date based on Today's date, you should create a measure:
WeekStartMeasure = TODAY()-WEEKDAY(Today(),2)+1
If you are creating week start date based on a column, then you should create a column with the following calculation:
WeekStartDate = Table[Date]- WEEKDAY(Table[Date],2)+1
Once you create the measure/column, you can use it in the visualization to get the desired result.
We can calculate this way also
if (
WEEKDAY(TODAY(),1) == 1,
TODAY(),
TODAY() - (WEEKDAY(TODAY(),1) - 1)
)
I have a calculation that is being done on a weekly basis (x+y/x*40) . 40 is the number of hrs worked per week and x is the num of weeks selected.
I have a relative date slicer using which the user will select the number of weeks. The catch is that there are two kinds of relative weeks - one from the present day and one is the entire week.
If the user selects 2 weeks it will be (x+y/2*40).
I have a calculation called
Tot Weeks = DATEDIFF(MIN( DimDate[Calendar Date] ), MAX( DimDate[Calendar Date]), week )
However, this doesn't work well if I select 'Weeks(Calendar Date)' in the drop down. For the value to be right, I created
Num weeks = DISTINCTCOUNT(DimDate[CalendarWeekOfYear])
Num weeks works fine only when 'Weeks(Calendar Date)' is selected. I am trying to retrieve the parameter passed to the slicer to get my values right.(whether the user selects 'Weeks(Calendar Date)' or 'Weeks' in the slicer).Is there a way to retrieve this or
Is there a way to combine these two?
If you have a slicer like with Weeks (Calendar Date) and Weeks as the two options in the column Slicer[WeekType], then you can pass your selection into a measure like this:
Weeks =
VAR WeekType = SELECTEDVALUE(Slicer[WeekType], <default>)
RETURN IF(WeekType = "Weeks", [Tot Weeks], [Num weeks])
I have a power bi report with a line chart that has a field called 'EventDate'
I need to add a filter on to this report to say 'only get me the days where the EventDate matches this week number'
I don't want to display the last 7 days as a relative filter.
I need to do it by this week.
Can anyone help
You can use the week in the relative date filtering and it returns the dates associated with the current week number rather than the last 7 days.