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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX function for average value per count data/rows

Hi,

 

I want to make a line chart for the value of the average [Decision Time (Days)] per count of [Notification] for each month.

The table is "Data". The fields are:

[Notification] (type: string)

[Date] (type: date)

[Decision Time (Days)] (type: number)

 

The formula will be something like:

AVGTIME = SUM([Decision Time (Days)]/COUNTA([Notification])

But it should be based on the counting per month.

 

Below is the sample data:

NotificationDateDecision Time (Days)
AAAA04/01/202015
BBBB02/04/202011
CCCC18/06/20207
DDDD01/01/202027
EEEE05/12/20205
FFFF06/01/202024
GGGG07/08/202015
HHHH08/08/202016
IIII09/08/20202
JJJJ10/08/202010
KKKK11/08/202026
LLLL12/05/202012
MMMM13/11/202019
NNNN15/03/202023


Thank you for your help.

This will be a live data so I hope I can get a formulation where I don't always need to update the field of the formula.

Regards,

Vano

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

your formula is already correct. All you need is to add a month column.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdBLDsMgDEXRvTCOZGMCIcM2/f82gNj/NvpsRIp6Z+jEDkkp7oDc5Hgm9iQsjIOPrk7FHZGSELSTN9qQnjJx6rSYnJAO+WGfNDojpUheOrU3XZBKGodmoytSWojz3/1uSCmPlIzuSGkdSEweSJ/jcYiNnsg+cRxq+15ICb8i7lNt4RvpKZD//cDV6IPsusRhXxhcrV8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Notification = _t, Date = _t, #"Decision Time (Days)" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Date.From([Date],"en-GB")),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Decision Time (Days)", type number}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Custom.1", each Date.Year([Custom])*100+Date.Month([Custom]))
in
    #"Added Custom1"

 

lbendlin_0-1611264074802.png

 

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

You may create a calculated column and a measure as below.

Calculated column:

YearMonth = YEAR([Date])*100+MONTH([Date])

 

Measure:

Result = 
DIVIDE(
   SUM('Table'[Decision Time (Days)]),
   DISTINCTCOUNT('Table'[Notification]),
   0
)

 

Result:

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

c1.png

 

You may create a calculated column and a measure as below.

Calculated column:

YearMonth = YEAR([Date])*100+MONTH([Date])

 

Measure:

Result = 
DIVIDE(
   SUM('Table'[Decision Time (Days)]),
   DISTINCTCOUNT('Table'[Notification]),
   0
)

 

Result:

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

your formula is already correct. All you need is to add a month column.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdBLDsMgDEXRvTCOZGMCIcM2/f82gNj/NvpsRIp6Z+jEDkkp7oDc5Hgm9iQsjIOPrk7FHZGSELSTN9qQnjJx6rSYnJAO+WGfNDojpUheOrU3XZBKGodmoytSWojz3/1uSCmPlIzuSGkdSEweSJ/jcYiNnsg+cRxq+15ICb8i7lNt4RvpKZD//cDV6IPsusRhXxhcrV8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Notification = _t, Date = _t, #"Decision Time (Days)" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Date.From([Date],"en-GB")),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Decision Time (Days)", type number}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Custom.1", each Date.Year([Custom])*100+Date.Month([Custom]))
in
    #"Added Custom1"

 

lbendlin_0-1611264074802.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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