Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi all,
I'm trying to figure out a way to get the number of months in the current year between two dates. So these dates can start in this and the previous year and can end in this or the next year. The two dates are in columns like below. Ideally I would need a DAX statement that would just give me a number and not need to create another table or multiple rows.
Any ideas?
Open Close # months in 2019 31/03/2018 31/04/2019 01/01/2019 01/11/2019 03/04/2019 01/03/2020
@donaldo - Perhaps try something like:
Measure 12 = VAR __start = IF(MAX('Table16'[Open])<DATE(2019,1,1),DATE(2019,1,1),MAX('Table16'[Open])) VAR __end = IF(MAX('Table16'[Close])>DATE(2019,12,31),DATE(2019,12,31),MAX('Table16'[Close])) VAR __table = GENERATESERIES(MONTH(__start),MONTH(__end)) RETURN COUNTX(__table,[Value])
Hi, I am unable to try it out right now.
Won't this create a table or at the very least rows with GENERATESERIES?
Is 2019 hardcoded here? As in this won't work upon entering 2020?
No, this just creates a temp table as a VAR in the measure itself, which it then uses to count all of the month numbers generated. It's probably overkill, you could just subtract the __start from the __end and add one but apparently I was feeling fancy. In the example, the 2019 is hard coded because I have no idea how you are actually planning on using it other than what you had in your post. If you had it in a matrix with a Year as columns, then you could just do something like DATE(MAX([Year]),1,1) for example. Those kinds of specifics are going to depend on your data and how you plan on using it. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Okay, cool. Right now I just need the it as part of a few other calculations I'm going to do. So it's not going into a visual. Sorry for not specifying.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
97 | |
77 | |
63 | |
55 |
User | Count |
---|---|
143 | |
109 | |
89 | |
84 | |
66 |