Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
Solved! Go to Solution.
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:
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
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))
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.
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:
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
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))
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.
Please attach the dummy PBIX file and required output.