Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
HI all,
I need to get the 1st day of last month (based on the current calendar month) into a measure but I have hit some confusion.
I started with,
FOM = DATE(YEAR(TODAY()), MONTH(TODAY()), 1)
and tried to wrap a DATEADD around it to decrement the month,
FOM = DATEADD((DATE(YEAR(TODAY()), MONTH(TODAY()), 1)), -1, MONTH)
the problem is that when I do that I get the error "The first argument do 'DATEADD' must specify a column but I have seen examples others have used when an expression or function has been passed in as the date. Can anyone see where I am going wrong or suggest another approach?
Thanks
Solved! Go to Solution.
Not really, I'm just considering the case that'll happen about 4 weeks from now where the measure that I've suggested will try to return a month of 0 and break. I've just plugged that suggestion into a measure and it's returning November 1st right now, so the whole thing should look something like:
PreviousMonthStart = if(month(today())=1,date(year(today())-1,12,1),date(year(today()),month(today())-1,1))
Might be missing a bracket somewhere
Can you try this? It worked for me... From what I understand you wanted the first day of last month. You can use this metric to get that:
FIRSTDAYOFMONTH = EOMONTH(TODAY(),-2)+1
Can you try this? It worked for me... From what I understand you wanted the first day of last month. You can use this metric to get that:
FIRSTDAYOFMONTH = EOMONTH(TODAY(),-2)+1
@fabianbram that is a much more elegant solution and it should handle the year chenage easily becasue they are all date based functions. Thank you very much
Your welcome!
Could you not try to just add a -1 after MONTH(TODAY()) into the first measure you listed, and then if that's working for anything that's not January, put in an if statement to handle that case and take one off the year instead while making the month December?
@jthomson Thanks very much for the reply.
I am still quite new to Power BI, DAX and M and I have had trouble writing the custom elements. Am I right in saying that for a measure I would need the IF which is used in DAX?
Thanks
Not really, I'm just considering the case that'll happen about 4 weeks from now where the measure that I've suggested will try to return a month of 0 and break. I've just plugged that suggestion into a measure and it's returning November 1st right now, so the whole thing should look something like:
PreviousMonthStart = if(month(today())=1,date(year(today())-1,12,1),date(year(today()),month(today())-1,1))
Might be missing a bracket somewhere
I have just seen your reply. Thanks very much, I have written the below and I guess I'll know if it can handle a year change properly in a few weeks!
FOM = IF(MONTH(TODAY()) <> 1, FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-1, 1),"DD/MM/YYYY"), FORMAT(DATE(YEAR(TODAY())-1, 12, 1),"DD/MM/YYYY") )
Thanks very much
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.