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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Nanakwame
Helper II
Helper II

Using SUMX with other functions

Hi Experts,

 

I currently have a dax function 

Margin % Today = CALCULATE(SUM(dailyKPI[Margin %]),'Date'[Date] = TODAY() -1) to calculate margin % for yesterday. This is being used in a table view so it sums up the total. please see the image attached. Instead of 315.4%, i will like for it to display the average of all the margin%. I will like for it not to sum the total but instead take the average and use it as total.
Also is there a way to exclude weekends when it is calculating yesterday's margin? for instance it will calculate friday's margin on monday instead of calculating sundays margin. 
 
Thanks in advance 
 
Nanakwame_0-1646108862590.png

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Nanakwame ,

On top this

Margin % Today = CALCULATE(SUM(dailyKPI[Margin %]),'Date'[Date] = TODAY() -1)

 

Create a new measure

averageX(values(dailyKPI[Warehouse]) , [Margin % Today])

View solution in original post

AllisonKennedy
Super User
Super User

@Nanakwame  I agree with @amitchandak  on how to get the average calculation. See my post here if you want to understand more why: https://excelwithallison.blogspot.com/2020/09/what-does-average-mean.html 

 

As for ignoring weekends, you can do this easily if you have a dimDate table that has a column that flags weekends or at very least a weekday column. 

https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html 

 

 It looks like you have a date table, so just depends on how you create the weekday column.

 

Assuming a 'Date'[Weekday] column that flags weekday as 1 and weekends as 0, the new measure would look something like: 

 

Margin % Today = 

VAR _Today = TODAY()

VAR _Yesterday = MAXX( FILTER( 'Date', 'Date'[Date] < _Today && 'Date'[Weekday] = 1 ), 'Date'[Date] )

RETURN

CALCULATE(SUM(dailyKPI[Margin %]),'Date'[Date] = _Yesterday)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
AllisonKennedy
Super User
Super User

@Nanakwame  I agree with @amitchandak  on how to get the average calculation. See my post here if you want to understand more why: https://excelwithallison.blogspot.com/2020/09/what-does-average-mean.html 

 

As for ignoring weekends, you can do this easily if you have a dimDate table that has a column that flags weekends or at very least a weekday column. 

https://excelwithallison.blogspot.com/2020/04/dimdate-what-why-and-how.html 

 

 It looks like you have a date table, so just depends on how you create the weekday column.

 

Assuming a 'Date'[Weekday] column that flags weekday as 1 and weekends as 0, the new measure would look something like: 

 

Margin % Today = 

VAR _Today = TODAY()

VAR _Yesterday = MAXX( FILTER( 'Date', 'Date'[Date] < _Today && 'Date'[Weekday] = 1 ), 'Date'[Date] )

RETURN

CALCULATE(SUM(dailyKPI[Margin %]),'Date'[Date] = _Yesterday)


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

amitchandak
Super User
Super User

@Nanakwame ,

On top this

Margin % Today = CALCULATE(SUM(dailyKPI[Margin %]),'Date'[Date] = TODAY() -1)

 

Create a new measure

averageX(values(dailyKPI[Warehouse]) , [Margin % Today])

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.