Forum Discussion
Calculate delta using slowly changing dimensions
- 1 year ago
You can create measures like
Products = VAR CurrentDate = MAX( 'Date'[Year month] ) VAR Result = CALCULATE( COUNTROWS( 'Table' ), 'Table'[Start date] <= CurrentDate && 'Table'[End date] > CurrentDate ) RETURN Result Newly Added = VAR CurrentDate = MAX( 'Date'[Year month] ) VAR Result = CALCULATE( COUNTROWS( 'Table' ), 'Table'[Start date] = CurrentDate ) RETURN Result Removed = VAR CurrentDate = MAX( 'Date'[Year month] ) VAR Result = CALCULATE( COUNTROWS( 'Table' ), 'Table'[End date] = CurrentDate ) RETURN Result Delta = [Newly Added] - [Removed] - Anonymous1 year ago
Hi Janou ,
Thank you johnt75 , for your excellent response! Your approach effectively captures newly added, removed, and delta values per month.
I’d like to expand on this with a small refinement to ensure products that end within the same month are correctly counted when calculating active products.
1.To ensure proper time intelligence calculations, first create a Date Table:
DateTable = CALENDAR(DATE(2024,1,1), DATE(2024,12,31))2.Create Newly added,removed and Delta calculation measures using following queries:-
Newly Added =CALCULATE(COUNTROWS('Products'),FILTER('Products',MONTH('Products'[Start Date]) = MONTH(MAX('DateTable'[Date])) &&YEAR('Products'[Start Date]) = YEAR(MAX('DateTable'[Date]))))
- Removed =
CALCULATE(COUNTROWS('Products'),FILTER('Products',MONTH('Products'[End Date]) = MONTH(MAX('DateTable'[Date])) &&YEAR('Products'[End Date]) = YEAR(MAX('DateTable'[Date])) &&'Products'[End Date] <= EOMONTH(MAX('DateTable'[Date]), 0)))
-
Delta = [Newly Added] - [Removed]
-
Now,plot a matrix visual then add MonthYear from DateTable to Rows field.
- Add [NewlyAdded], [Removed], and [Delta] to Values filed.
-
Now, you will get the desired output.
If our answer meets your requirement,consider accepting it as solution.
Thank you for being a part of Microsoft Fabric Community Forum!
Regards,
Pallavi. -
- Anonymous1 year ago
Hi Janou ,
As we have not received a response from you yet, I would like to confirm whether you have successfully resolved the issue or if you require further assistance.
If the issue has been resolved, please mark the helpful reply as a "solution" to indicate that the question has been answered and to assist others in the community.
Thank you for your cooperation. Have a great day.
Hi Janou ,
Thank you johnt75 , for your excellent response! Your approach effectively captures newly added, removed, and delta values per month.
I’d like to expand on this with a small refinement to ensure products that end within the same month are correctly counted when calculating active products.
1.To ensure proper time intelligence calculations, first create a Date Table:
-
Newly Added =CALCULATE(COUNTROWS('Products'),FILTER('Products',MONTH('Products'[Start Date]) = MONTH(MAX('DateTable'[Date])) &&YEAR('Products'[Start Date]) = YEAR(MAX('DateTable'[Date]))))
- Removed =
CALCULATE(COUNTROWS('Products'),FILTER('Products',MONTH('Products'[End Date]) = MONTH(MAX('DateTable'[Date])) &&YEAR('Products'[End Date]) = YEAR(MAX('DateTable'[Date])) &&'Products'[End Date] <= EOMONTH(MAX('DateTable'[Date]), 0)))
-
Delta = [Newly Added] - [Removed]
-
Now,plot a matrix visual then add MonthYear from DateTable to Rows field.
- Add [NewlyAdded], [Removed], and [Delta] to Values filed.
-
Now, you will get the desired output.
If our answer meets your requirement,consider accepting it as solution.
Thank you for being a part of Microsoft Fabric Community Forum!
Regards,
Pallavi.