Forum Discussion
Syndicate_Admin
3 years agoAdministrator
Dax problem
Dear good afternoon I want to ask for your help to be able to perform the following measure or generacy to achieve the following I have the following data enterprise Date ini End date Monthl...
Syndicate_Admin
3 years agoAdministrator
Start date
MFelix
3 years agoSuper User
Try the following formula:
Values per Month =
VAR temptable =
ADDCOLUMNS (
FILTER (
ADDCOLUMNS (
CROSSJOIN (
DISTINCT('Calendar'[Year]),
ADDCOLUMNS (
'DataValues',
"StartYear", YEAR ( 'DataValues'[Date ini] ),
"EndYear", YEAR ( 'DataValues'[End date] )
)
),
"Flag",
IF ( [StartYear] <= [Year] && [EndYear] >= [Year], 1, 0 )
),
[Flag] = 1
),
"TotalMonths",
SWITCH (
TRUE (),
[StartYear] = [Year],
DATEDIFF (
'DataValues'[Date ini],
MIN ( DATE ( [year], 12, 31 ), 'DataValues'[End date] ),
MONTH
) + 1,
[StartYear] > [Year], DATEDIFF ( DATE ( YEAR ( [StartYear] ), 12, 31 ) + 1, 'DataValues'[Date ini], MONTH ),
[StartYear] < [Year]
&& [EndYear] > [Year], DATEDIFF ( DATE ( [Year], 1, 1 ), DATE ( [Year], 12, 31 ), MONTH ) + 1,
[EndYear] = [Year], DATEDIFF ( DATE ( [year], 1, 1 ), 'DataValues'[End date], MONTH ) + 1
)
)
RETURN
SUMX ( tempTable, [TotalMonths] * 'DataValues'[Monthly Value] )
Don't forget to accept the correct answer to help others.