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
MYDATASTORY
Resolver I
Resolver I

How calculate Average sale by country and date

I  have below data and I would like to calculate Average sales county and month,  I have converted  date as Month slicer which looks like May 2020, May 2021, June 1988, Feb 2020 (DD/MM/YYYY)

ID  Country   Date              Sales

1   USA          1/2/2020       100

2  USA          2/2/2020         200

 

The average will be (100+200)divide 2 = 150

ID   Country       Date                 Sales

1   USA          1/2/2020       100

2  USA           2/2/2020         200

3  SPAIN       2/05/2020       300

4SPAIN         4/6/1988         100 

 

I tried below DAX but was not filtering properly when you click two months slicer

Spoiler
Averagex = AVERAGEX(VALUES('Sales Table'[Date]),[Total Sales])

I also tried below,
Country Sales =
 
Spoiler
CALCULATE(AVERAGEX(
'Sales Table','Sales Table'[Sales]),
FILTER(ALL('Sales Table'),
'Sales Table'[Country ]=SELECTEDVALUE('Sales Table'[Country ])) )
 

I would like to slice (Slicer) the data by country and Month from date column to be able to get the correct Average even when two months i.e June 1988, Feb 2020 are selected.

Thanks 

 

 

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi , @MYDATASTORY 

Try to create a calculate column first:

Year_month = FORMAT('Sales Table'[Date ],"MMM yy")

Then create a measure as below:

Avg = CALCULATE(AVERAGE('Sales Table'[Sales]),ALLEXCEPT('Sales Table','Sales Table'[Country],'Sales Table'[Year_month]))

 9.png

pbix attached

 

Best Regards,
Community Support Team _ Eason
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-easonf-msft
Community Support
Community Support

Hi , @MYDATASTORY 

Try to create a calculate column first:

Year_month = FORMAT('Sales Table'[Date ],"MMM yy")

Then create a measure as below:

Avg = CALCULATE(AVERAGE('Sales Table'[Sales]),ALLEXCEPT('Sales Table','Sales Table'[Country],'Sales Table'[Year_month]))

 9.png

pbix attached

 

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

harshnathani
Community Champion
Community Champion

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.