Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
spandy34
Responsive Resident
Responsive Resident

Average - Distinct Count

I have the matrix below  which has a Distinct Count of field [Claim Ref] within the Table named INS_Main Claim Data by Calendar Month.

 

I would like a column at the end after March column which has the Average for each year for each Class of Business

 

How would I write the DAX for this please?

 

 

spandy34_1-1712064599412.png

 

@amitchandak @tamerj1 @danextian @goncalogeraldes @v-tangjie-msft @v-kaiyue-msft @Uzi2019 

1 ACCEPTED SOLUTION
spandy34
Responsive Resident
Responsive Resident

Hi

I resolved this by

  • Creating a column in the INS_Main Claim Data table and called it [AverageCountColumn] which placed a number 1 in each row of the table
  • Within the same table I created a field called Month_Year which was the Notification Date in the format of

 Notification Month Year = FORMAT([NotificationDate]," mmm yyyy")

  • I created a measure which calculated a distinctcount of the notification month year:-

 

Z_Count of Month_Year = (DISTINCTCOUNT('INS_Main Claim Data'[Notification Month Year]))

 

  • I created a measure of the count of the total claim refs:-

 

z_Generic_No of Claims Distinct = DISTINCTCOUNT('INS_Main Claim Data'[ClaimRef])

 

  • I created an average measure

 

z_1Average = DIVIDE([z_Generic_No of Claims Distinct],[Z_Count of Month_Year])

 

  • I then created the matrix

 

spandy34_0-1718090193881.png

 

 

  • I created the matrix and hid all the average fields apart from the average total

 

spandy34_1-1718090193884.png

 

 

Using a slicer I can now create the a table below which calculates the average based on the number of distinct month year values.  I am sure there is a cleverer way to do this using DAX but with my limited knowledge this solution has worked.

 

View solution in original post

14 REPLIES 14
v-yaningy-msft
Community Support
Community Support

Hi, @spandy34 

Here, thanks for @lbendlin reply. You can refer to his reply, and if it didn't work, you can share the pbix file without sensitive data, or share the datasheet, measure, etc. that will enable you to simulate your matrix.

Best Regards,
Yang
Community Support Team

Calendar Table

 

DateCalMonthCalYearDateid
03/07/1899Jul189918990703
08/07/1901Jul190119010708
07/07/1902Jul190219020707
06/07/1903Jul190319030706
04/07/1904Jul190419040704
03/07/1905Jul190519050703
08/07/1907Jul190719070708
06/07/1908Jul190819080706
05/07/1909Jul190919090705
04/07/1910Jul191019100704
03/07/1911Jul191119110703
08/07/1912Jul191219120708
07/07/1913Jul191319130707
06/07/1914Jul191419140706
05/07/1915Jul191519150705

lbendlin_0-1717769279493.png

 

spandy34
Responsive Resident
Responsive Resident

Hi

Thank you for the pbix file.

I need an Average Column next to the Total field so will have the following

 

To include

                Total     Average

EL          17          1.54                     17/ 11 months) = 1.54

IN           5             0.45

ML         25          2.27

MV         5             0.45

OT          5             0.45

PL          6             0.54

PR          4             0.36

Total     67          6.09

lbendlin_0-1717777233875.png

 

spandy34
Responsive Resident
Responsive Resident

Below I have a column called z_Average with the following.  At the moment it is dividing distinct count of the Claim Ref, by the distinct count of the month year.  How do it amend it so it divides by the count of the month_year which in the example should be 3 (April 2024, June 2024 and May 2024) as opposed to 1 month.

 

z_Average = DIVIDE(DISTINCTCOUNT('INS_Main Claim Data'[ClaimRef], DISTINCTCOUNT('INS_Fin_Calendar Main Claim Data Notification Date'[month_year]))

 

 

spandy34_0-1717793770237.png

 

You will have to define what to do with months that you have selected but that have no data. Should they be considered for the average or not?

spandy34
Responsive Resident
Responsive Resident

No they should not be considered only the months with data 

Personally I don't agree with that methodology.  Maybe someone else can help you further.

spandy34
Responsive Resident
Responsive Resident

Hi

I resolved this by

  • Creating a column in the INS_Main Claim Data table and called it [AverageCountColumn] which placed a number 1 in each row of the table
  • Within the same table I created a field called Month_Year which was the Notification Date in the format of

 Notification Month Year = FORMAT([NotificationDate]," mmm yyyy")

  • I created a measure which calculated a distinctcount of the notification month year:-

 

Z_Count of Month_Year = (DISTINCTCOUNT('INS_Main Claim Data'[Notification Month Year]))

 

  • I created a measure of the count of the total claim refs:-

 

z_Generic_No of Claims Distinct = DISTINCTCOUNT('INS_Main Claim Data'[ClaimRef])

 

  • I created an average measure

 

z_1Average = DIVIDE([z_Generic_No of Claims Distinct],[Z_Count of Month_Year])

 

  • I then created the matrix

 

spandy34_0-1718090193881.png

 

 

  • I created the matrix and hid all the average fields apart from the average total

 

spandy34_1-1718090193884.png

 

 

Using a slicer I can now create the a table below which calculates the average based on the number of distinct month year values.  I am sure there is a cleverer way to do this using DAX but with my limited knowledge this solution has worked.

 

spandy34
Responsive Resident
Responsive Resident

The months in the matrix are governed by a slicer so depending how many months are selected will determine how many months the average is divided by so we cant hard code it to 11 as you state in 

Average = divide(COUNTROWS('Table'),11,0)
 
for example below when I select 2024-25 financial year we only have April to June .  I think its difficult putting an average column in a matrix
 
spandy34_0-1717788592992.png

 

 

Hi  

Here is the data table linked to a calendar table by Dateid_NotificationDate

 

Claim RefClassOfBusinessCodeNotificationDateDateid_NotificationDate
7313IN23/11/199919991123
7395IN03/04/200020000403
13029IN15/12/200420041215
12922IN24/10/200420041024
12921IN23/10/200420041023
25967EL20/03/201220120320
25010EL10/05/201120110510
25009EL10/05/201120110510
25008EL10/05/201120110510
25007EL10/05/201120110510
25006EL10/05/201120110510
24897EL04/04/201120110404
24877EL25/03/201120110325
24862EL22/03/201120110322
24844EL21/03/201120110321
24843EL21/03/201120110321
24842EL21/03/201120110321
24791EL08/03/201120110308
24790EL08/03/201120110308
24723EL15/02/201120110215
24599EL21/01/201120110121
24598EL21/01/201120110121
24511ML23/12/201020101223
24510ML23/12/201020101223
24477ML14/12/201020101214
24476ML14/12/201020101214
24474ML14/12/201020101214
24473ML14/12/201020101214
24472ML14/12/201020101214
24471ML14/12/201020101214
24350ML10/11/201020101110
24284ML26/10/201020101026
24249ML18/10/201020101018
24191ML28/09/201020100928
24190ML28/09/201020100928
24177ML24/09/201020100924
24176ML24/09/201020100924
24125ML15/09/201020100915
23957ML21/07/201020100721
23956ML21/07/201020100721
23883ML07/07/201020100707
23879ML07/07/201020100707
23878ML07/07/201020100707
23876ML07/07/201020100707
23875ML07/07/201020100707
23791ML22/06/201020100622
23790ML22/06/201020100622
10942MV03/02/200320030203
10122MV18/09/200220020918
9870MV23/07/200220020723
19447MV22/04/200820080422
18774MV28/01/200820080128
18057OT19/09/200720070919
18358OT15/11/200720071115
17210OT12/07/200720070712
17282OT23/07/200720070723
26217OT29/05/201220120529
26216PL29/05/201220120529
26215PL29/05/201220120529
26214PL29/05/201220120529
26213PL29/05/201220120529
26212PL29/05/201220120529
26295PL29/06/201220120629
26294PR29/06/201220120629
26293PR29/06/201220120629
26292PR29/06/201220120629
26273PR22/06/201220120622
lbendlin
Super User
Super User

no need for DAX.  Specify the value aggregation as Average, and enable Column totals.

spandy34
Responsive Resident
Responsive Resident

Hi  When you say specify the value aggregation as Average and enable Columns, Im a bit unsure how to do it.  Please can you suggest how I change the format below.  Many thanks

The Matrix is made up of

 

Rows  -               Class of Business Code

                                Year

Columns           CalMonth

Values                Count of Claims

spandy34_0-1717765327990.png

 

spandy34_1-1717765327992.png

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.