Power BI DAX, END OF MONTH DOESN'T WORK WITH DATE TABLE - powerbi

When using endofmonth dax statement with my fact table it works:
EOM =
CALCULATE(
SUM('Table'[sales]),
ENDOFMONTH('Table'[date])
)
However when I use it with my date table it returns blanks does anyone know why?
dax command using my date table:
EOM_DTBLE =
CALCULATE(
SUM('Table'[sales]),
ENDOFMONTH('DATE'[Date])
)

You need to check what end of month returns first:
If we test it with a simple code:
Test = CALCULATE(ENDOFMONTH('Date'[Date]))
So basically, It returns the last date of each month. If you have no data in the end of the month specified, It returns empty.
If you have data (I have 679 on 31/01/2022) then, Code returns:

Related

IF 'AND-OR' ISFILTERED combination in DAX giving problems

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.

Power BI Measure to return date if the condition is true

I am struggling in writing a measure which returns me the list of dates if the condition is true.
For example, Last 7 days, I was able to do it in calculated column as below
Last 7 days = if(DateTime[Datetime]<=TODAY(),DateTime[DateTime])
The problem with the calculated column is when I am using this column as a filter, It is showing the dates that are not the last 7 days as blanks which I dont want. Please help.
Since you want to return a list of dates you need a Calculated Table:
Last 7 days =
FILTER(
'Datetime',
AND(
'Datetime'[Datetime] > TODAY() - 7,
'Datetime'[Datetime] <= TODAY()
)
)
You can use this table to filter your other data.

Get year of end date within date between

I use as a filter date between.
I would like to get the year of the end date. I try as measure yearmax=year(max(date)) but it returns wrong values. I need to extract only the year of the end date. For example, when the user select as date range 01/03/2020 till 04/04/2027, I need to get only the year of the end date and have 2027.
I put the pbix file here, any help would be appreciated.
https://drive.google.com/file/d/1AqrdiHBQdYjrQImP9AGO_sC7Duh9Yeb5/view?usp=drivesdk
This looks like a Power BI slicer visual bug.
You set filter into the slicer to restrict the selection over the last 90 days including TODAY. When selecting any day up to yesterday, your YEAR(MAX('Date'[Date])) measure works fine. But when you push the slicer up to today, then even if the slicer shows the correct date of today in the upper bound, the measure returns the last year in the date table, like when no filter exists. To fix that you might add a filter to your measure to limit the upper bound to TODAY() like follows
Year end date =
VAR MaxDate =
CALCULATE ( MAX ( 'Date'[Date] ), KEEPFILTERS ( 'Date'[Date] <= TODAY () ) )
RETURN
YEAR ( MaxDate )
Of course, maybe that the problem was just the existence of the filter in the slicer, and by removing it the original measure works ad desired

Date diff using dates in the same column DAX

I have a dataset where I am trying to calculate the user response time to dealer note using the note date of every action.
Here is my sample data look like, I've calculated this in hive query using lag, lead, and min window functions, but my user wants to see this in Power BI.
This is what I tried so far.
I've created a "user note date" measure to get the first response of the User response
user note date = CALCULATE(MIN(Query1[Note Date]),ALLEXCEPT(Query1,Query1[incident],Query1[Action Type]),
LEFT(Query1[lastuser],1) in {"U"} )
Dealer Note Date =
CALCULATE(
MIN(Query1[pdate]),
FILTER(ALLEXCEPT(Query1,Query1[incident],Query1[action_type]),
Query1[action_type] in {
"DLR_CUST_Update"
))
I am getting this error from Dealer Note Date Measure, I am not understanding what's wrong with the above calculation.
error: A single value for column 'Action Type' in table 'Query1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min
Here is my sample data
Your column in calculation for [Dealer Note Date] is query1[action_type] or Query1[Action Type]??
You cant access column Query1[action_type] in [Dealer Note Date], because you are excluding it in ALLEXCEPT
Dealer Note Date =
CALCULATE(
MIN(Query1[pdate]),
FILTER(ALLEXCEPT(Query1,Query1[incident],**Query1[action_type]**),
Query1[action_type] in {
"DLR_CUST_Update"
))

power bi dax last value over a period

I have this table below. How to get Revenue_MTD in DAX? Revenue_MTD equals to the revenue of the last month of each year. The tables are from Tableau and I am converting these to power bi.
with only years:
If you want to get the revenue of the same month previous year you can add a calculated column with this type of dax expression :
Revenue_MTD = SUM(Revenue),
PARALLELPERIOD(
[Date],
-12,
MONTH)
)
you can have more detail on this link :
https://radacad.com/dateadd-vs-parallelperiod-vs-sameperiodlastyear-dax-time-intelligence-question
This is a standard powerbi measure, it should be fairly easy for you to implement this.
MEASURE = CLOSINGBALANCEYEAR(,[,][,])
.
.
.
MEASURE = CLOSINGBALANCEYEAR(SUM(Revenue), DATE )
As long as you have a Date column with appropriate Date Column it should work.
then create another measure with only SUM(revenue)
What expression are you using for your [Revenue_MTD]? Are you using the built-in DAX function TOTALMTD?