Forum Discussion
DAX Calculate Countrows, average per Year per Weekday
- 4 years ago
Hi bkoenen ,
How about this:
Here the measure:
Average Countrows per Year per Weekday = VAR _helpTable = SUMMARIZE ( Table, Table[Day of the week], "NumberOfDayOfTheWeek", COUNT ( Table[Day of the week] ), "DistinctNumberOfDates", DISTINCTCOUNT ( Table[Date] ) ) RETURN MAXX (_helpTable, [NumberOfDayOfTheWeek] ) / MAXX (_helpTable, [DistinctNumberOfDates] )And here how the helpTable would look like:
Let me know if this helps or if you have any questions ๐
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/ - 4 years ago
Hi, bkoenen
You can try the following methods.
Measure:
Result = VAR _N1 = CALCULATE ( DISTINCTCOUNT ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), [Day of the week] = SELECTEDVALUE ( 'Table'[Day of the week] ) ) ) VAR _N2 = CALCULATE ( COUNT ( 'Table'[Day of the week] ), FILTER ( ALL ( 'Table' ), [Day of the week] = SELECTEDVALUE ( 'Table'[Day of the week] ) ) ) RETURN DIVIDE ( _N2, _N1 )COUNT: https://docs.microsoft.com/dax/count-function-dax
DISTINCTCOUNT: https://docs.microsoft.com/dax/distinctcount-function-dax
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi bkoenen ,
I created a measure instead of a calculated column ๐
try a measure instead and see whether it works!
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Hello Tom,
When I use the example with the Measure it works correct, but when I use it in the original report the average results are different then when you calculate it.
Left results are the picking orders per Monday, there are 13 Mondays. Calculation: 9392 / 13 = 722
Our calculation says there is an average of 2789 on Mondays? Any idea what goed wrong?
Kind regards Bjรถrn
- daXtreme4 years agoSolution Sage
[Your Column] = // a calc column, not a measure var thisYear = year( T[Date] ) var dayOfWeek = T[Day of Week] var RowsOfInterest = filter( T, year( T[Date] ) = thisYear && T[Day Of Week] = dayOfWeek ) var numOfSameWeekdays = countrows( RowsOfInterest ) var numOfDifferentDates = distinctcount( selectcolumns( RowsOfInterest, "@Date", T[Date] ) ) var ratio = numOfSameWeekdays / numOfDifferentDates return ratio- bkoenen4 years agoHelper I
Hello daXtreme,
I get an error message for the Distinctcount function, any idea?
Kind regards Bjรถrn
- daXtreme4 years agoSolution Sage
Change to this:
[Your Column] = // a calc column, not a measure var thisYear = year( T[Date] ) var dayOfWeek = T[Day of Week] var RowsOfInterest = filter( T, year( T[Date] ) = thisYear && T[Day Of Week] = dayOfWeek ) var numOfSameWeekdays = countrows( RowsOfInterest ) var numOfDifferentDates = countrows( distinct( selectcolumns( RowsOfInterest, "@Date", T[Date] ) ) ) var ratio = numOfSameWeekdays / numOfDifferentDates return ratio