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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
StevenT
Helper V
Helper V

Get count of months data was larger or smaller than the previous month

Hi, is there a way to calculate how many times a record has values that are higher or lower than the previous month, as compared to going down the next month?

For example,
To calculate how many increases
in the first record the result would be 2, since only Feb and May show an increase
in the second record result would be 3, since Feb Apr and May show increases

To calculate how many decreases
in the first record the result would be 3, since only Jan March and Apr show an increase
in the second record result would be 3, since Jan and March show decreases

StevenT_1-1726251176363.png

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi,elitesmitpatel ,thanks for your concern about this issue.
And I would like to share some additional solutions below.

Hello,@StevenT.I am glad to help you.
According to your description, you want to calculate the number of times the measure [%diff] is greater than 0 or less than 0 (the number of times it has gone up or down compared to the previous month).
The count function does not work directly on the measure in Desktop, so I suggest that you first create a dummy table (using the summalize or filter function to specify the table) that meets the criteria for the measure of the drink.
Below is my test:
This is my test data: 

vjtianmsft_0-1726463656231.png
These are my test measures, in order to restore your real data as much as possible.

lastValue = 
VAR _date=MAX('Table'[Date])
VAR _lastValue=CALCULATE(MAX('Table'[C_Sales]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date]=EDATE(_date,-1)))
RETURN _lastValue

 

%Diff = 
VAR _result=IF(ISBLANK([lastValue]),0,
DIVIDE([lastValue]-MAX('Table'[C_Sales]),MAX('Table'[C_Sales]))
)
RETURN
_result

 

vjtianmsft_1-1726463756203.png

You can use the following code to calculate the result you want to achieve:

_countDrop = COUNTROWS(FILTER(ALLEXCEPT('Table','Table'[ID]),[%Diff]<0))



_countRise = COUNTROWS(FILTER(ALLEXCEPT('Table','Table'[ID]),[%Diff]>0))

vjtianmsft_2-1726463802519.png

It should be noted that the calculation results of measure is very dependent on your computing environment (filtering in the code and external visual and filters, slicer field filtering), so you need to modify the dax code according to your actual needs to calculate the mesaure to meet your actual data.I provide the test code for reference only.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
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

I'm going to try this out and definitely mark the Accept as Solution button.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,elitesmitpatel ,thanks for your concern about this issue.
And I would like to share some additional solutions below.

Hello,@StevenT.I am glad to help you.
According to your description, you want to calculate the number of times the measure [%diff] is greater than 0 or less than 0 (the number of times it has gone up or down compared to the previous month).
The count function does not work directly on the measure in Desktop, so I suggest that you first create a dummy table (using the summalize or filter function to specify the table) that meets the criteria for the measure of the drink.
Below is my test:
This is my test data: 

vjtianmsft_0-1726463656231.png
These are my test measures, in order to restore your real data as much as possible.

lastValue = 
VAR _date=MAX('Table'[Date])
VAR _lastValue=CALCULATE(MAX('Table'[C_Sales]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date]=EDATE(_date,-1)))
RETURN _lastValue

 

%Diff = 
VAR _result=IF(ISBLANK([lastValue]),0,
DIVIDE([lastValue]-MAX('Table'[C_Sales]),MAX('Table'[C_Sales]))
)
RETURN
_result

 

vjtianmsft_1-1726463756203.png

You can use the following code to calculate the result you want to achieve:

_countDrop = COUNTROWS(FILTER(ALLEXCEPT('Table','Table'[ID]),[%Diff]<0))



_countRise = COUNTROWS(FILTER(ALLEXCEPT('Table','Table'[ID]),[%Diff]>0))

vjtianmsft_2-1726463802519.png

It should be noted that the calculation results of measure is very dependent on your computing environment (filtering in the code and external visual and filters, slicer field filtering), so you need to modify the dax code according to your actual needs to calculate the mesaure to meet your actual data.I provide the test code for reference only.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



I'm going to try this out and definitely mark the Accept as Solution button.

elitesmitpatel
Super User
Super User

Please attach the dummy PBIX file and required output.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors