Forum Discussion
TechR21
Helper V
3 years agoAdding row with a calculation to matrix visual
Hi, In powerbi I have a simple matrix visual : - subscriptionname as row - month as column - sum of costs as value Im trying to find a way to add the following to this matrix (or ...
- Anonymous3 years ago
Hi TechR21 ,
I suggest you to create a Calendar table to help your calculation.
Calendar = ADDCOLUMNS ( CALENDARAUTO (), "Year", YEAR ( [Date] ), "Month", MONTH ( [Date] ), "YearMonth", YEAR ( [Date] ) * 100 + MONTH ( [Date] ), "Month-Year", FORMAT ( [Date], "MMMM-YY" ) )Data model:
Measure:
Percentage Change by Month = VAR _CURRENT = CALCULATE ( SUM ( 'Table'[Costs] ) ) VAR _PREVIOUS = CALCULATE ( SUM ( 'Table'[Costs] ), PREVIOUSMONTH ( 'Calendar'[Date] ) ) RETURN IF ( _CURRENT = BLANK (), BLANK (), DIVIDE ( _CURRENT - _PREVIOUS, _PREVIOUS ) )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TomMartens
Super User
3 years agoHey TechR21 ,
I recommend reading this article: https://www.daxpatterns.com/time-patterns/
The article contains almost everything necessary to know regarding calendar based calculations.
It explains how you create a dedicated calendar table, relate this to your fact table(s), and how to create dynamic date based calculations.
Regards,
Tom