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)
)
Related
Below is the sample dataset
The data has two slicers ( date and category ) shown below
I am writing a DAX Statement to multiply the sum(values) * 10 only if the date range is in the current year 2023.
The StartYear gives the start of the current year, firstD gives the lowest date from the date slicer.
Formula =
var new = sum(Test[Value]) * 10
var startyear = DATE(YEAR(TODAY()),1,1)
var firstD = CALCULATE( MIN( Test[Date]), ALLSELECTED(Test[Date]) )
return if( ISFILTERED(Test[Categories]) && firstD >= startyear, new, 0 )
Now when I filter dates to 2023, the total value should be 2300 but it shows as 0
However the DAX works when I select A or B
If we remove the ISFILTERED function then, it gives wrong value, the expected value is 0 because the start date is in 2022, but it shows 650
let me know if that is the right syntax
It looks like you are not using a separate calendar table to handle this, which you need!
In your very last example you have set your slicer to some time late 2022, but the minimum value of 'Test'[Date] for your selected category is in year 2023. Hint: set the slicer to e.g. 2022-12-14, this will include a 2022-date for Category A in your data.
Your measure behaves exactly how it is supposed to, in other words!
To fix this, you need to do the following:
Create a calendar table in your model, this should contain contiguous dates, which is necessary for the filtering method you want
Establish a relationship between the calendar table and existing Test table.
Use the date column from your new calendar table in your slicer and as date reference in your measure
Exactly how to create a calendar table is thoroughly documented on Google, I recommend you search and find an article or video you understand for implementing this.
Lastly: Your use of ISFILTERED in this measure seems strange, since you mention nowhere the requirement of only showing a number if the column you are testing filtering on is filtered, if that makes sense.. :-) The way you describe your calculation, you only need to check whether the selected date range starts in current year.
Can you help me figure out how to display sales data by "WEEKS" in power BI visuals ? I have a calendar table and the date hierarchy is listed by Year, Quarter, Month and Day with no week option.the visual I'd like to create is the chart at the bottom of the image I have attached Thanks
You need to add in the Week to your calendar.
If your are using DAX there are a number of ways
To show the week number of the year use WEEKNUM
Week No = WEEKNUM(Table1[Date], 2)
For the start of the week in a date format use
Start of Week = 'Calendar'[Date] - WEEKDAY('Calendar'[Date],2) +1
The equivalent functions in Power Query are Date.WeekOfYear and Date.StartOfWeek
I am building a report in Power BI Desktop, created a slicer - YearMonthSort - which has data selection by Year-Month
Plz, see the screenshot below:
My goal is to limit data in this slicer as -
2015-07 to today's date
(whichever it will be when users will look at the data,
in the same format - "YYYY-MM")
In the "Filters" section I can select my starting year as 2015-07,
but having problem setting today's date.
I tried to create the new Measure, but not sure where to place it,
or, may be there is another way to perform this:
IsToday = FORMAT(TODAY(), "mm/yyyy")
I only just started to learn this,
Thank you for help in advance!
You can do the following:
I am assuming that you are using a calendar table that is joined to your fact table on a date field and that your year sort column is calculated with reference to the 'date' field in your calendar table.
Assuming, this is true you can create a calculated column that will flag whether or not the date field is before or after today. This can be achieved by using the following DAX:
IsToday =
SWITCH (
TRUE (),
'Calendar'[Date]
<= NOW (), 1,
0
)
Then, in your visual add a 'Visual Level Filter' using this new column and set it to 1.
I am trying to calculate the number of working days between two dates in PowerBI excluding the weekends.
So, I have a table called as Calendar which has the date coming from 2000-2030 and another table which has the submitted date and today's date.
Where am I going wrong in this? My Calculated field Aging is showing wrong values and I cannot Identify why this is happening.
Tried with a measure and it says single value for Submitted_Date cannot be determined.
Aging2 = CALCULATE(SUM('Calendar'[IfWorkDay]),DATESBETWEEN('Calendar'[Date],(AgingReport[Submitted_Date]),(AgingReport[Today's Date])))
As a Column:
_dc_Vol_TTR_BDays = // BusinessDays
SUMX(
SELECTCOLUMNS(
CALENDAR([_scCreatedDateYMD], [_scLastActiveDateYMD]),
"Date", [_scCreatedDateYMD],
"BDay", IF(WEEKDAY([Date],3) < 5, 1, 0)
),
[BDay]
)
The Problem was with the data type. They both needs to be on the same date type.
I've used the new Quick Measures feature of Power BI to build a 3 month rolling average calculation and it's working well. The equation is displayed below. However, when I try to use this metric in a time series visualization, the calculations are displaying three months past the current month, but I'd like for the calculation to stop at the current month.
I've played around with the __DATE_PERIOD variable to no avail. My date filter for the page is set to show all dates in the current months or 12 months prior via a calculated column on the date table.
Is anyone aware of how I can get the visualization to end at the current month?
Average Days to Close Rolling Average =
IF(
ISFILTERED('Date'[Date]),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy."),
VAR __LAST_DATE =
ENDOFMONTH('Date'[Date].[Date])
VAR __DATE_PERIOD =
DATESBETWEEN(
'Date'[Date].[Date],
STARTOFMONTH(DATEADD(__LAST_DATE, -3, MONTH)),
__LAST_DATE
)
RETURN
AVERAGEX(
CALCULATETABLE(
SUMMARIZE(
VALUES('Date'),
'Date'[Date].[Year],
'Date'[Date].[QuarterNo],
'Date'[Date].[Quarter],
'Date'[Date].[MonthNo],
'Date'[Date].[Month]
),
__DATE_PERIOD
),
CALCULATE(
'Closed Opportunities'[Average Days to Close],
ALL('Date'[Date].[Day])
)
)
)
In order to limit what is displayed within your chart, you need to filter the applicable date field so it only displays the dates you desire. In this case, you only want it to include dates <= today.
In order to automatically filter it when it is refreshed, I typically add a custom DAX column to the date table that I can filer on. In this case it would be something along the lines of:
excludeFutureDatesInd = 'Date'[Date] <= TODAY()
You can then add a visual, page, or report filter selecting all dates where [excludeFutureDatesInd] = True.
Not sure if you're still having issues with this, but I'd like to share a hack fix for those landing here. I fixed this issue by filtering on the base data (in your example, this would be "Average Days to Close"). Set a visual-level filter to include only those items where Average Days to Close > 0, and you should get the extra dates cut off the end of the graph.
So long as all of your base data passes through the filter, you should be good.