March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
Register NowGet certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
I have measure _CurrentDateValueMPreviousDateValue and i want find the period between months with minus _CurrentDateValueMPreviousDateValue.
https://drive.google.com/file/d/1CgDLgj0NzLY384LBMkJr5cGmCnAkbgIQ/view?usp=sharing
Solved! Go to Solution.
Hi @Fighting21
The calculation of measures is dynamic and dependent on the current context, using measures to achieve your desired effect can be challenging.
Please consider using calculated columns to do it.
1. Create a column to calculate the difference between the current row and the previous row:
Difference =
VAR PrevDate =
CALCULATE(
MAX('DataTable'[Date]),
FILTER(
'DataTable',
'DataTable'[Category] = EARLIER('DataTable'[Category]) &&
'DataTable'[SubCategory] = EARLIER('DataTable'[SubCategory]) &&
'DataTable'[Date] < EARLIER('DataTable'[Date])
)
)
VAR PrevValue =
CALCULATE(
MAX('DataTable'[Value]),
FILTER(
'DataTable',
'DataTable'[Category] = EARLIER('DataTable'[Category]) &&
'DataTable'[SubCategory] = EARLIER('DataTable'[SubCategory]) &&
'DataTable'[Date] = PrevDate
)
)
RETURN
IF(ISBLANK(PrevValue), 'DataTable'[Value], 'DataTable'[Value] - PrevValue)
2. Create a column to calculate the month interval between negative values:
MonthsBetweenNegativeValues =
VAR CurrentDate = 'DataTable'[Date]
VAR CurrentCategory = 'DataTable'[Category]
VAR CurrentSubCategory = 'DataTable'[SubCategory]
VAR PreviousNegativeDate =
CALCULATE(
MAX('DataTable'[Date]),
FILTER(
'DataTable',
'DataTable'[Category] = CurrentCategory &&
'DataTable'[SubCategory] = CurrentSubCategory &&
'DataTable'[Date] < CurrentDate &&
'DataTable'[Difference] < 0
)
)
RETURN
IF(
'DataTable'[Difference] < 0,
IF(
ISBLANK(PreviousNegativeDate),
BLANK(),
DATEDIFF(PreviousNegativeDate, CurrentDate, MONTH)
),
BLANK()
)
Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Fighting21
The calculation of measures is dynamic and dependent on the current context, using measures to achieve your desired effect can be challenging.
Please consider using calculated columns to do it.
1. Create a column to calculate the difference between the current row and the previous row:
Difference =
VAR PrevDate =
CALCULATE(
MAX('DataTable'[Date]),
FILTER(
'DataTable',
'DataTable'[Category] = EARLIER('DataTable'[Category]) &&
'DataTable'[SubCategory] = EARLIER('DataTable'[SubCategory]) &&
'DataTable'[Date] < EARLIER('DataTable'[Date])
)
)
VAR PrevValue =
CALCULATE(
MAX('DataTable'[Value]),
FILTER(
'DataTable',
'DataTable'[Category] = EARLIER('DataTable'[Category]) &&
'DataTable'[SubCategory] = EARLIER('DataTable'[SubCategory]) &&
'DataTable'[Date] = PrevDate
)
)
RETURN
IF(ISBLANK(PrevValue), 'DataTable'[Value], 'DataTable'[Value] - PrevValue)
2. Create a column to calculate the month interval between negative values:
MonthsBetweenNegativeValues =
VAR CurrentDate = 'DataTable'[Date]
VAR CurrentCategory = 'DataTable'[Category]
VAR CurrentSubCategory = 'DataTable'[SubCategory]
VAR PreviousNegativeDate =
CALCULATE(
MAX('DataTable'[Date]),
FILTER(
'DataTable',
'DataTable'[Category] = CurrentCategory &&
'DataTable'[SubCategory] = CurrentSubCategory &&
'DataTable'[Date] < CurrentDate &&
'DataTable'[Difference] < 0
)
)
RETURN
IF(
'DataTable'[Difference] < 0,
IF(
ISBLANK(PreviousNegativeDate),
BLANK(),
DATEDIFF(PreviousNegativeDate, CurrentDate, MONTH)
),
BLANK()
)
Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you very much, sorry for accept it as the solution lately.
Hi @Fighting21
I don't know what you mean by 'month between'. Please show an example of the result you want, including the sub-categories you've mentioned.
Regards
Phil
Proud to be a Super User!
Thank you for reply i upgraded my question.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
Check out the November 2024 Power BI update to learn about new features.
User | Count |
---|---|
60 | |
31 | |
22 | |
19 | |
19 |