Hello all PowerBI geniuses, I am still studying the courses and sadly got another question.
I already have a solution to my problem, I was just wondering if there is a smarter way to do it.
I want to calculate cumulative total revenue per quarter for -1 year. The way I managed to calculate this was by using measure “Test1”. The problem is that I want to make measure “Test 2” work, how do I do it? Essentially, I want a formula that tells PowerBI to go -1 year and select the first available quarter with that of that year.
Revenu QC = Calculate every year`s cumulative total revenue
VAR SelectedYear = SELECTEDVALUE(‘Dim_Calendar (Q)’[Year])
Return
CALCULATE([Revenue Q],
FILTER(ALLSELECTED(‘Dim_Calendar (Q)’),
‘Dim_Calendar (Q)’[Year_Quarter]<=MAX(‘Dim_Calendar (Q)’[Year_Quarter]) &&
‘Dim_Calendar (Q)’[Year]=SelectedYear
)
)
Test 1 = Calculate the previous year`s cumulative total using an index column that is stored in the
VAR CurrentYear = SELECTEDVALUE(‘Dim_Calendar (Q)’[Year])
VAR CurrentQuarter = SELECTEDVALUE(Dim_Calendar[#Quarter])
VAR Index = Selectedvalue(‘Dim_Calendar (Q)’[Index])VAR CurrentRevenue = CALCULATE([Revenue Q],
FILTER(ALLSELECTED(‘Dim_Calendar (Q)’),
‘Dim_Calendar (Q)’[Year_Quarter]<=MAX(‘Dim_Calendar (Q)’[Year_Quarter]) &&
‘Dim_Calendar (Q)’[Year]=CurrentYear
)
)VAR PreviousRevenue = CALCULATE([Revenue Q],
FILTER(ALLSELECTED(‘Dim_Calendar (Q)’),
‘Dim_Calendar (Q)’[Index]<=Index-4 &&
‘Dim_Calendar (Q)’[Year]=CurrentYear-1
)
)Return
PreviousRevenue
Test 2 = Should calculate the same thing as a measure “Test1”, but this actually calculates previous year total revenue.
VAR CurrentYear = SELECTEDVALUE(‘Dim_Calendar (Q)’[Year])
VAR CurrentRevenue = CALCULATE([Revenue Q],
FILTER(ALLSELECTED(‘Dim_Calendar (Q)’),
‘Dim_Calendar (Q)’[Year_Quarter]<=MAX(‘Dim_Calendar (Q)’[Year_Quarter]) &&
‘Dim_Calendar (Q)’[Year]=CurrentYear
)
)VAR PreviousRevenue = CALCULATE([Revenue Q],
FILTER(ALLSELECTED(‘Dim_Calendar (Q)’),
‘Dim_Calendar (Q)’[Year_Quarter]<=MAX(‘Dim_Calendar (Q)’[Year_Quarter]) &&
‘Dim_Calendar (Q)’[Year]=CurrentYear-1
)
)Return
PreviousRevenue