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
PSVSupp1913
Regular Visitor

Calculate average on table with multiple dimensions

I have the following table:
D

DateLocationClientValue
2023-03-21A115
2023-03-21A210
2023-03-21A325
2023-03-21B130
2023-03-22A115
2023-03-22A210
2023-03-22A325
2023-03-22B130
2023-03-23A15
2023-03-23A25
2023-03-23B15

 

I want to create a visual with the average, depending on the selected data.

For example, I want to see the average of pallets per customer per day, if I select 2023-03-21 / 2023-03-22. 

That should be:

ClientAverage
145
210
325

 

I thought I should use Avg = sum( [Value]) / DISTINCTCOUNT ( Date ) but then I get this:

ClientAvg
122,5
210
325

 

What should I do to resolve this?

2 ACCEPTED SOLUTIONS
v-binbinyu-msft
Community Support
Community Support

Hi @PSVSupp1913 ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1679623670075.png

2. create a measure with below dax formula

Avg =
VAR min_date =
    MINX ( 'Table', [Date] )
VAR max_date =
    MAXX ( 'Table', [Date] )
VAR tmp =
    FILTER ( 'Table', 'Table'[Date] >= min_date && 'Table'[Date] <= max_date )
VAR tmp1 =
    CALCULATETABLE ( VALUES ( 'Table'[Date] ), tmp )
VAR _val =
    SUMX ( tmp, [Value] )
VAR _ctn =
    COUNTROWS ( tmp1 )
RETURN
    DIVIDE ( _val, _ctn )

3. add a table and slicer visual

vbinbinyumsft_1-1679623728162.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-binbinyu-msft
Community Support
Community Support

Hi @PSVSupp1913 ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1679623670075.png

2. create a measure with below dax formula

Avg =
VAR min_date =
    MINX ( 'Table', [Date] )
VAR max_date =
    MAXX ( 'Table', [Date] )
VAR tmp =
    FILTER ( 'Table', 'Table'[Date] >= min_date && 'Table'[Date] <= max_date )
VAR tmp1 =
    CALCULATETABLE ( VALUES ( 'Table'[Date] ), tmp )
VAR _val =
    SUMX ( tmp, [Value] )
VAR _ctn =
    COUNTROWS ( tmp1 )
RETURN
    DIVIDE ( _val, _ctn )

3. add a table and slicer visual

vbinbinyumsft_1-1679623728162.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks, that works as well!

But I found another solution. By adding a measure in the data table, Total=sum([Value]), the Dax average worked. Avg = [Total] / DISTINCTCOUNT ( [Date] ).

 

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.