Forum Discussion
Struggling to get the average
- Anonymous1 year ago
Hi Nico83 , hello Ritaf1983, thank you for your prompt reply!
Please check if the following measures meet your requirements:Average Inbound Calls = VAR SelectYear = SELECTEDVALUE('Table'[DATE].[Year]) VAR SelectMonth = SELECTEDVALUE('Table'[Month]) VAR SelectDay = SELECTEDVALUE('Table'[DATE].[Day]) VAR LastDayOfMonth = EOMONTH(DATE(SelectYear, SelectMonth, 1), 0) VAR DaysInMonth = DAY(LastDayOfMonth) VAR DaysInYear = DATEDIFF(DATE(SelectYear, 1, 1), DATE(SelectYear, 12, 31), DAY) RETURN SWITCH( TRUE(), NOT(ISBLANK(SelectDay)), CALCULATE(COUNTROWS('Table'), 'Table'[INBOUND] = "Inbound") / 1, NOT(ISBLANK(SelectMonth)), CALCULATE(COUNTROWS('Table'), 'Table'[INBOUND] = "Inbound") / DaysInMonth, NOT(ISBLANK(SelectYear)), CALCULATE(COUNTROWS('Table'), 'Table'[INBOUND] = "Inbound") / DaysInYear, BLANK() )Average Outbound Calls = VAR SelectYear = SELECTEDVALUE('Table'[DATE].[Year]) VAR SelectMonth = SELECTEDVALUE('Table'[Month]) VAR SelectDay = SELECTEDVALUE('Table'[DATE].[Day]) VAR LastDayOfMonth = EOMONTH(DATE(SelectYear, SelectMonth, 1), 0) VAR DaysInMonth = DAY(LastDayOfMonth) VAR DaysInYear = DATEDIFF(DATE(SelectYear, 1, 1), DATE(SelectYear, 12, 31), DAY) RETURN SWITCH( TRUE(), NOT(ISBLANK(SelectDay)), CALCULATE(COUNTROWS('Table'), 'Table'[OUTBOUND] = "Outbound") / 1, NOT(ISBLANK(SelectMonth)), CALCULATE(COUNTROWS('Table'), 'Table'[OUTBOUND] = "Outbound") / DaysInMonth, NOT(ISBLANK(SelectYear)), CALCULATE(COUNTROWS('Table'), 'Table'[OUTBOUND] = "Outbound") / DaysInYear, BLANK() )Result:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous1 year ago
Hi Nico83 ,
Thank you for your feedback.Per my test, I created month, year and day numeric columns for the slicer:
You could also change the SelectMonth variable in both measures as shown below without creating these columns:
VAR SelectMonth = SELECTEDVALUE('Table'[DATE].[MonthNo])Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Nico83 , hello Ritaf1983, thank you for your prompt reply!
Please check if the following measures meet your requirements:
Average Inbound Calls =
VAR SelectYear = SELECTEDVALUE('Table'[DATE].[Year])
VAR SelectMonth = SELECTEDVALUE('Table'[Month])
VAR SelectDay = SELECTEDVALUE('Table'[DATE].[Day])
VAR LastDayOfMonth = EOMONTH(DATE(SelectYear, SelectMonth, 1), 0)
VAR DaysInMonth = DAY(LastDayOfMonth)
VAR DaysInYear = DATEDIFF(DATE(SelectYear, 1, 1), DATE(SelectYear, 12, 31), DAY)
RETURN
SWITCH(
TRUE(),
NOT(ISBLANK(SelectDay)),
CALCULATE(COUNTROWS('Table'), 'Table'[INBOUND] = "Inbound") / 1,
NOT(ISBLANK(SelectMonth)),
CALCULATE(COUNTROWS('Table'), 'Table'[INBOUND] = "Inbound") / DaysInMonth,
NOT(ISBLANK(SelectYear)),
CALCULATE(COUNTROWS('Table'), 'Table'[INBOUND] = "Inbound") / DaysInYear,
BLANK()
)
Average Outbound Calls =
VAR SelectYear = SELECTEDVALUE('Table'[DATE].[Year])
VAR SelectMonth = SELECTEDVALUE('Table'[Month])
VAR SelectDay = SELECTEDVALUE('Table'[DATE].[Day])
VAR LastDayOfMonth = EOMONTH(DATE(SelectYear, SelectMonth, 1), 0)
VAR DaysInMonth = DAY(LastDayOfMonth)
VAR DaysInYear = DATEDIFF(DATE(SelectYear, 1, 1), DATE(SelectYear, 12, 31), DAY)
RETURN
SWITCH(
TRUE(),
NOT(ISBLANK(SelectDay)),
CALCULATE(COUNTROWS('Table'), 'Table'[OUTBOUND] = "Outbound") / 1,
NOT(ISBLANK(SelectMonth)),
CALCULATE(COUNTROWS('Table'), 'Table'[OUTBOUND] = "Outbound") / DaysInMonth,
NOT(ISBLANK(SelectYear)),
CALCULATE(COUNTROWS('Table'), 'Table'[OUTBOUND] = "Outbound") / DaysInYear,
BLANK()
)
Result:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Joyce
Thank you so much for your assistance so far. I am trying to place this in a table visual and am getting the error message MdxScript(Model) (40,47) Calculation error, cannot convert value 'November' of type Text to type Integer. Any suggestions?
Best Regards
Nic
- Anonymous1 year agoNot applicable
Hi Nico83 ,
Thank you for your feedback.Per my test, I created month, year and day numeric columns for the slicer:
You could also change the SelectMonth variable in both measures as shown below without creating these columns:
VAR SelectMonth = SELECTEDVALUE('Table'[DATE].[MonthNo])Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.