March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello.
I need to calculate the following formula, but based on specific months (ie April to September 2021, 2022)
x = number + number + sum(data in a table). I think I need to use DATESINPERIOD. but I don`t know how to select the months.
I have a date table (01/01/2019 to present, I will need April to Sept 21 and 22)
How could I do it?
Solved! Go to Solution.
Hi @Alexandra_B ,
According to your description, I create a sample.
Here's my solution, create a measure.
X =
VAR _Sum =
CALCULATE (
SUM ( 'BB_EGLF_CDD_15 5C_till_june22'[CDD 15.5] ),
FILTER (
ALL ( 'BB_EGLF_CDD_15 5C_till_june22' ),
MONTH ( 'BB_EGLF_CDD_15 5C_till_june22'[Month] )
IN { 4, 5, 6, 7, 8, 9 }
&& YEAR ( 'BB_EGLF_CDD_15 5C_till_june22'[Month] ) IN { 2019, 2020, 2021, 2022 }
)
)
RETURN
42180.2942 + 68.8235277 * _Sum
Here I only return the sum and get the correct result.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please considerAccept it as the solution to help the other members find it more quickly.
Hi @Alexandra_B ,
According to your description, I create a sample.
Here's my solution, create a measure.
X =
VAR _Sum =
CALCULATE (
SUM ( 'BB_EGLF_CDD_15 5C_till_june22'[CDD 15.5] ),
FILTER (
ALL ( 'BB_EGLF_CDD_15 5C_till_june22' ),
MONTH ( 'BB_EGLF_CDD_15 5C_till_june22'[Month] )
IN { 4, 5, 6, 7, 8, 9 }
&& YEAR ( 'BB_EGLF_CDD_15 5C_till_june22'[Month] ) IN { 2019, 2020, 2021, 2022 }
)
)
RETURN
42180.2942 + 68.8235277 * _Sum
Here I only return the sum and get the correct result.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please considerAccept it as the solution to help the other members find it more quickly.
Thank you 🙂
@Alexandra_B Try this
var a = calculate ( sum (data in table ) , DATESBETWEEN ( your date column , Start date , End date))
return number + number + a
Hello, @Anonymous .
Thank you for your reply.
I have tried, but I get the following error.
The syntax for 'return' is incorrect.
(DAX(CALCULATE (SUM( 'BB_EGLF_CDD_15 5C_till_june22'[CDD 15.5] ), DATESBETWEEN('BB_EGLF_CDD_15 5C_till_june22'[Month], DATE(2021,04,01), DATE(2021,09,30)))return "42180.2942" + "68.8235277" * 'a')).
I am doing it wrong?
Create a measure
x =
var a =CALCULATE (SUM( 'BB_EGLF_CDD_15 5C_till_june22'[CDD 15.5] ),
DATESBETWEEN('BB_EGLF_CDD_15 5C_till_june22'[Month],
DATE(2021,04,01),
DATE(2021,09,30))
return 42180.2942 + 68.8235277 * a
What if I need for all the years same months , 2019 - 2022? That means I cannot use DATESBETWEEN for it... 😞
yes correct, Datesbetween wont work there.
can you show what exactly you are trying to achive.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
82 | |
69 | |
53 | |
44 |
User | Count |
---|---|
202 | |
106 | |
100 | |
64 | |
56 |