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
calculate Number of month is a year as per my below it return 11 it should be 10 screenshot below. what will be dax query
Example1 for contract 10A040-06. End date is 10/31/2021 therefore calculation should be 10 . Currently it showing is 11
Example2 for contract 10101204. End date is 2/28/2022 therefore calculation should be 12. Currently it showing is 11
Number of service month =
Solved! Go to Solution.
Hi, @mdaamirkhan
I wrote the last formula based on the logic you said.
And you said 'A per your query For Feb 2022 it will be 2 not 12. If 2023 then it will be 12' ,So I modify the measure.
Like this:
Number of service month =
VAR _start =
STARTOFYEAR ( 'Table'[date] )
VAR _yr =
YEAR ( NOW () )
VAR _end =
DATE ( _yr, 12, 31 )
VAR b =
DATEDIFF ( _end, _start, MONTH )
VAR year =
YEAR ( MAX ( 'Table'[date] ) )
RETURN
IF ( year = _yr, MONTH ( _start ), IF ( year > _yr, b ) )
If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
It's not clear to me what your logic is intended to do.
Why should 10/31/2021 give 10 and 2/28/2022 give 12?
because it not count whole year as per current month.
If I have in a year 2021 fronm Jan to dec then as per date 10/31/2021 it should count as 10 monthsin a year
OK. 10 months for 10/31 is easy to understand but you did not explain why 2/28 should give 12. Why not 2 or 14 or something else?
logic will be this
revenue this year = if("contract end date"- 01/01/this year)<12 then ("contract end date"- 01/01/this year) else 12
revenue this year+1 = if("contract end date"- 01/01/this year+1)<12 then ("contract end date"- 01/01/this year+1) else 12
Hi, @mdaamirkhan
You can modify your measure like this:
Number of service month =
VAR _start =
STARTOFYEAR ( 'Table'[date] )
VAR _yr =
YEAR ( NOW () )
VAR _end =
DATE ( _yr, 12, 31 )
VAR a =
DATEDIFF ( _start, _end, MONTH )
RETURN
IF ( a < 12 && a > 0, MONTH ( _start ), IF ( a < 0, 12 ) )
If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
A per your query For Feb 2022 it will be 2 not 12. If 2023 then it will be 12
Hi, @mdaamirkhan
I wrote the last formula based on the logic you said.
And you said 'A per your query For Feb 2022 it will be 2 not 12. If 2023 then it will be 12' ,So I modify the measure.
Like this:
Number of service month =
VAR _start =
STARTOFYEAR ( 'Table'[date] )
VAR _yr =
YEAR ( NOW () )
VAR _end =
DATE ( _yr, 12, 31 )
VAR b =
DATEDIFF ( _end, _start, MONTH )
VAR year =
YEAR ( MAX ( 'Table'[date] ) )
RETURN
IF ( year = _yr, MONTH ( _start ), IF ( year > _yr, b ) )
If it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
When I use this query [Number of service month_2] its not showing the value for Current year +1 , Current year +2 and Current year +3.
Can you please help me on this what is the issue in the below dax or in [Number of service month that you have provided .
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 |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
148 | |
111 | |
93 | |
84 | |
66 |