Using Date Range from a Slicer in a DAX Query PowerBI - powerbi

I have a date slicer that is controlled by the user. I am trying to use the users min/max date selection as a indicator. I have created two measures - one for the min value and another measure for the max value. Please see DAX code for one below:
NewMin = CALCULATE(FIRSTDATE('Master Query'[RegisterDate]),ALLSELECTED('Master Query'))
Now, on the Master Query Table there is a column that holds date values in the format of dd/mm/yyyy 00:00:00...I am adding another column and using a if statement to get a 0/1 output (i.e. checking if the date column is between the min and max date slicer selection) but it is not working. See DAX Below:
RangeCheck = IF('Master Query'[RegisterDate] >= 'Master Query'[NewMin] && 'Master Query'[RegisterDate] <= 'Master Query'[NewMax],1,0)
This does not work and I am unsure as to why. It seems its not recognising the dates or cant decipher if date is between the two min and max boundries.

A calculated column cannot read in dynamic filters from slicers. Calculated columns are only computed once per time the model is refreshed, not in response to interaction slicers or the filter pane.
In contrast, measures do work for dynamic calculations (though not when you try to use them within a calculated column).

Related

DAX count rows but not for future dates

I've got 3 tables. First is a date table that only has dates. Second is my actual values and third is my projected. Actuals and Projected are both related to the date table (1 to many single direction)
Trying to plot actual vs projected on a line graph, using the dates column from the dates table and a measure from each of the other two. This is my measure for actual values: count = calculate(counta(actual[product]))+0. The issue is then the graph shows 0s for all future dates where I only want my projected line to show up. Is there a different measure I can use to not show the 0 for the future date and be blank instead?
Try this
count = calculate(counta(actual[product]),
'Date'[Date] <= max(Date[Date)
)
Please note that Date: your calendar table,
[Date ] is column in side the Date table.
Please let me know if your issue has been resolved.

Calendar/GenerateSeries DAX functions giving error "The start date or end date in Calendar function can not be Blank value."

I am trying to create a separate table that will have dates between Start_Date and End_date. These dates are measures. Below is the detail of my requirement..
I have a Dropdown in report which lists distinct dates of fact.sales table and is a single select. I am saving this selected date in a Measure --> End_Date = selectedvalue(sale[Delivery Date Key]).
Now I am showing a report using what-if parameter. The slider slides from values 1 to 24.
Now I am creating another Measure..
Start_Date = date(year('Date'[End Date]),MONTH('Date'[End Date])-Cust_Key[Cust_Key Value],1)`
The Problem - When I try to use calendar function to create table using below DAX function, I get an error - "The start date or end date in Calendar function can not be Blank value."
calendar = calendar('Date'[Start Date],'Date'[End Date])
Can measures not be used inside the Calendar/GenerateSeries function.. Thanks in advance..
The SELECTEDVALUE function will return a blank if you haven't selected a single value. Note that calculated tables cannot read slicer values since they are only computed when the data is loaded, not whenever you interact with a slicer. Therefore, your End_Date measure returns a blank since it isn't filtered by the slicer.
You can use measures within any calculated tables but they won't interact with any dynamic slicers or filters. Calculated tables in your data model are static once the model is loaded. You can, however, use temporary/dynamic calculated tables within a measure so long as the measure still returns a single value at the end.

Need to limit the date in a slicer by today's date in Power BI

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.

Subtracting measure value from each row of a table in Microsoft Power BI

I have created two slicers in Power BI for Month and Year. These take the month and year value and in return generate a date.
Eg. Month - May & Year- 2019 generates 01/05/2019 with the help of the a measure formula :
MyFilterDate = DATE(SELECTEDVALUE(ListoY[Year]),SELECTEDVALUE(ListoM[Month],0),"01")
I want to subtract this date with one that is already in a column in the table.
I'm facing an issue when I try to subtract the measure from the existing column by writing DAX.
SUBVALNEW = DATEDIFF([MyFilterDate],Table[Date],DAY)
But when I try to do so, the result is not right. In fact when I try to check the value of [MyFilterDate] in the Data Model, it is not the same value as one calculated in the measure. (It instead looks like it displays the date in Table[Date])
Is there any way to subtract a Dynamically chosen date from a date in a column?
Any help would be appreciated.
I understand what your thinking patern is but power bi works a bit different. Dynamic measures cannot be used with calculated columns. When doing so the value of the measure is not set.
The way to go about this is by creating a Date table:
Date = CALENDAR(MIN(CalendarWeek[Date]);MAX(CalendarWeek[Date]))
Do NOT connect it to the model. From here you can make 2 slicers (based on the Date table). One your set to the month and the other to the year.
Next step is to adjust the MyFilterDate
MyFilterDate = DATE(SELECTEDVALUE('Date'[Date].[Year]);SELECTEDVALUE('Date'[Date].[MonthNo]);"01")
Make SUBVALNEW a measure (cannot be a column because it is dynamic!)
SUBVALNEW = DATEDIFF([MyFilterDate];SELECTEDVALUE(CalendarWeek[Date]) ;DAY)
Ass the Measuer to your visual, see end result below)

Power bi - Use Slicer selection in filtering data

I am new to Power bi but i want to use Slicer(user selection) while filter data with comparison by 'Greater Than' instead of equal to.
I have data of devices with LastUpdated date column. and slicer with few list of dates for 15 days gap (calendar would be better but as it is not available yet sticking with dates list)
When user select a date in Slicer i want to filter the data whose Lastupdated Date is greater than equal to selected date. How to achieve this? tried columns,measures..
Any help is appreciated.
I think you can create a measure that links the Date list table and the Device table, even if there is no relationship between them. However the measure must be present in your visualization otherwise the slicer will not affect it.
I've created a measure that calculates the maximum date for those rows which last update date is greater or equal than the slicer selection.
CalculatedLastUpdate =
CALCULATE (
MAX ( DeviceTable[LastUpdate] ),
FILTER (
DeviceTable,
DeviceTable[LastUpdate] >= MINX ( DateList, DateList[Date] )
)
)
DateList - a table containing a column [Date] with you date range.
DeviceTable - a table containing device data.
Now you can delete LastUpdate column from your visualization in order to avoid two columns with the same data.
Let me know if it helps.
I don't know about earlier , but now you can modify the date slicer to do as "after" the given date (you can do so by clicking on the icons present in the rightmost side of the slicer visual itself , wher you can select mode of slicer as between , after ,list , dropdown etc.)...which I believe means that you get all data for dates greater than the selected dates for the given column used in slicer which in your case will be LastUpdate.