참고 답변
I place the Period column in a slicer. When the user changes the slicer, the measure switches dynamically.
To improve readability, I add conditional formatting. For example, I apply icon formatting so positive values show an upward arrow and negative values show a downward arrow. I usually pair this with color formatting to make trends immediately visible.
To summarize, here's what I do: a properly structured date table, clean time intelligence measures, safe percentage calculations using DIVIDE, and a disconnected parameter table to control dynamic behavior. Once those pieces are in place, the report becomes flexible without complicating the model.I start with the date table. Time intelligence does not work reliably without a proper date dimension.
I make sure the model has a continuous date table with no gaps and with columns like Year, Quarter, Month, and Week. The Date column must contain every date in the range. Then I mark it as the official Date Table in Power BI. Without a contiguous date column, functions like SAMEPERIODLASTYEAR won't behave correctly.
Once the date table is in place, I build the base measure first:
Total Sales = SUM(Sales[Amount])
Then I create comparison measures.
For Year-over-Year:
YoY Sales =
[Total Sales]
- CALCULATE(
[Total Sales],
SAMEPERIODLASTYEAR(DateTable[Date])
)
For Quarter-over-Quarter:
QoQ Sales =
[Total Sales]
- CALCULATE(
[Total Sales],
DATEADD(DateTable[Date], -1, QUARTER)
)
For Month-over-Month:
MoM Sales =
[Total Sales]
- CALCULATE(
[Total Sales],
DATEADD(DateTable[Date], -1, MONTH)
)
After absolute differences, I usually create percentage change measures. I use DIVIDE instead of the division operator to handle division-by-zero safely.
For example:
YoY % =
DIVIDE(
[YoY Sales],
CALCULATE([Total Sales], SAMEPERIODLASTYEAR(DateTable[Date]))
)
Now, for dynamic selection, I create a disconnected parameter table with values like YoY, QoQ, and MoM. This table does not have a relationship with the sales table. It only drives measure selection.
Then I create a switching measure:
Selected Comparison =
SWITCH(
SELECTEDVALUE(PeriodTable[Period]),
"YoY", [YoY Sales],
"QoQ", [QoQ Sales],
"MoM", [MoM Sales]
)