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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
bsheffer
Continued Contributor
Continued Contributor

need to add up number of times the current month total is greater than the prior month total

for each account I need to add up the number of times the current month sales totals is greater than the prior month total for a filtered period on the page

 

Seems like summarize should do it but I think I have to build a summary table in the measure as the table to use in the summarize statement.  Any ideas how to best do this?

 

 

1 ACCEPTED SOLUTION

Hi @bsheffer 

you can try this measure

Measure = 
var _currentMonth=CALCULATE(MAX('Table'[activity_month]),ALL('Table'))
var _sales=CALCULATE(MIN('Table'[total_sales_amount]),FILTER(ALLEXCEPT('Table','Table'[merchant_number]),'Table'[activity_month]=_currentMonth))
var _count=IF(_sales=0,0,CALCULATE(COUNTROWS('Table'),FILTER(ALL('Table'),'Table'[merchant_number]=MIN('Table'[merchant_number])&&'Table'[activity_month]<_currentMonth&&'Table'[total_sales_amount]<_sales)))
return IF(ISBLANK(_count),0,_count)

result

vxiaotang_0-1627634076359.png

 

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

5 REPLIES 5
v-xiaotang
Community Support
Community Support

Hi @bsheffer 

In fact, your solution is not common. A more general approach is to create a table,

I find several models, you can try this way, (This way is more efficient)

https://community.powerbi.com/t5/Desktop/Calendar-Table/m-p/1860460

 

or if you can share your sample data or sample file without sensitive information, then I can write specified measure for your sample.

 

 

Best Regards,

Community Support Team _Tang

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

bsheffer
Continued Contributor
Continued Contributor

here is some sample data

 

merchant_numbertotal_sales_amountactivity_month
11506/1/2021
11005/1/2021
1504/1/2021
2506/1/2021
2405/1/2021
21004/1/2021
31005/1/2021
3504/1/2021
4506/1/2021

 

a measure that uses this data should show the result in a table of merchant_number and months_improved

 

merchant_numbermonths_improved
12
21
30
40

 

6/1/2021 is the current month.  Merchant 3 should have a value of 0 because it doesn't have activity in the current month.  Merchant 4 should have 0 because it only has 1 month of activity.

Hi @bsheffer 

you can try this measure

Measure = 
var _currentMonth=CALCULATE(MAX('Table'[activity_month]),ALL('Table'))
var _sales=CALCULATE(MIN('Table'[total_sales_amount]),FILTER(ALLEXCEPT('Table','Table'[merchant_number]),'Table'[activity_month]=_currentMonth))
var _count=IF(_sales=0,0,CALCULATE(COUNTROWS('Table'),FILTER(ALL('Table'),'Table'[merchant_number]=MIN('Table'[merchant_number])&&'Table'[activity_month]<_currentMonth&&'Table'[total_sales_amount]<_sales)))
return IF(ISBLANK(_count),0,_count)

result

vxiaotang_0-1627634076359.png

 

 

Best Regards,

Community Support Team _Tang

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

bsheffer
Continued Contributor
Continued Contributor

I was able to complete it by brute force but I think there has to be a more elegant solution.  Here is the code I wrote.  I tested back 8 months but really the maximum number of months improved has been 4

 

_months_improved =
var _month = max('Fact Cubes'[ACTIVITY_MONTH])
var _monthdates = DATESINPERIOD('Dim Calendar ActivityMonth'[Date], _month, 1, MONTH)
var _monthimproved0 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, 0, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -1, MONTH))> 0, 1, 0)
var _monthimproved1 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -1, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -2, MONTH))> 0, 1, 0)
var _monthimproved2 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -2, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -3, MONTH))> 0, 1, 0)
var _monthimproved3 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -3, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -4, MONTH))> 0, 1, 0)
var _monthimproved4 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -4, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -5, MONTH))> 0, 1, 0)
var _monthimproved5 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -5, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -6, MONTH))> 0, 1, 0)
var _monthimproved6 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -6, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -7, MONTH))> 0, 1, 0)
var _monthimproved7 = if(calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -7, MONTH)) - calculate([_TOTAL_SALES_VOLUME_AMEX], all('Dim Calendar ActivityMonth'), DATEADD(_monthdates, -8, MONTH))> 0, 1, 0)
return
if(_monthimproved0 + _monthimproved1 + _monthimproved2 + _monthimproved3 + _monthimproved4 + _monthimproved5 + _monthimproved6 + _monthimproved7 = 8, 8,
if(_monthimproved0 + _monthimproved1 + _monthimproved2 + _monthimproved3 + _monthimproved4 + _monthimproved5 + _monthimproved6 = 7, 7,
if(_monthimproved0 + _monthimproved1 + _monthimproved2 + _monthimproved3 + _monthimproved4 + _monthimproved5 = 6, 6,
if(_monthimproved0 + _monthimproved1 + _monthimproved2 + _monthimproved3 + _monthimproved4 = 5, 5,
if(_monthimproved0 + _monthimproved1 + _monthimproved2 + _monthimproved3 = 4, 4,
if(_monthimproved0 + _monthimproved1 + _monthimproved2 = 3, 3,
if(_monthimproved0 + _monthimproved1 = 2, 2,
if(_monthimproved0 = 1, 1,
0)
)
)
)
)
)
)
)
 
I'm using it in a table with account, count of improved months for a 2 year period w sorting on improved months from highest to lowest.
v-xiaotang
Community Support
Community Support

Hi @bsheffer 

this requirement seems to be possible without building a summary table. But for details, I need to look at your sample data. could you share your sample data or sample file after removing sensitive data?

 

Any question, please let me know. looking forward to receiving your reply.

 

Best Regards,

Community Support Team _Tang

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

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.