Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
EugenioProlog
Helper I
Helper I

How to create time grain selector with a Growth % Calculator?

I have this simple report below, that shows my TotalSales of the month, and my Sales Growth % comparing to last month.

I need to do two things:

1 - create a Time Grain selector, in order to choose to see the data Monthly, Quarterly or Yearly.
2 - I need my Sales Growth % metric to reflect the choice on this selector.

How can I do that?

Here is the link to my pbix file: https://drive.google.com/file/d/1ilt40d75TqNTt3OLjwvYGhy4b5flmXmH/view?usp=sharing

EugenioProlog_0-1738948016099.png

 

1 ACCEPTED SOLUTION

@EugenioProlog,

 

The switch measure needs to match the names in the field parameter. For example, instead of dsc_mesano, I renamed the field (in the field parameter) to Monthly.

 

Parâmetro-TimeGrain = {
    ("Monthly", NAMEOF('dim__calendario'[dsc_mesano]), 0),
    ("Quarterly", NAMEOF('dim__calendario'[dsc_trimestre]), 1),
    ("Yearly", NAMEOF('dim__calendario'[num_ano]), 2)
}

 

The switch measure uses Monthly:

 

Switch Measure = 
SWITCH (
    MAX ( 'Parâmetro-TimeGrain'[Parâmetro-TimeGrain] ),
    "Monthly", [Sales Growth % Monthly],
    "Quarterly", [Sales Growth % Quarterly],
    "Yearly", [Sales Growth % Yearly]
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@EugenioProlog,

 

This solution uses a field parameter (create it via the UI and then modify the DAX as needed):

 

Time_Grain_Parameter = {
    ("Monthly", NAMEOF('dim__calendario'[dsc_mesano]), 0),
    ("Quarterly", NAMEOF('dim__calendario'[qtr_year]), 1),
    ("Yearly", NAMEOF('dim__calendario'[num_ano]), 2)
}

 

https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters 

 

You can add columns or measures to a field parameter. Since the requirement is to display the data according to the selected time grain, I created a field parameter using date table columns.

 

I created additional measures using your monthly template:

 

Sales Growth % Quarterly = 
VAR CurrentSales = [TotalSales]
VAR PreviousSales = 
    CALCULATE(
        [TotalSales], 
        DATEADD(dim__calendario[dt_date], -1, QUARTER) -- Ajuste para o nível de tempo desejado
    )
RETURN 
    IF(NOT ISBLANK(PreviousSales), 
       DIVIDE(CurrentSales - PreviousSales, PreviousSales, 0), 
       BLANK()
    )
Sales Growth % Yearly = 
VAR CurrentSales = [TotalSales]
VAR PreviousSales = 
    CALCULATE(
        [TotalSales], 
        DATEADD(dim__calendario[dt_date], -1, YEAR) -- Ajuste para o nível de tempo desejado
    )
RETURN 
    IF(NOT ISBLANK(PreviousSales), 
       DIVIDE(CurrentSales - PreviousSales, PreviousSales, 0), 
       BLANK()
    )

 

To determine which measure to display (per the field parameter slicer), create this measure:

 

Switch Measure = 
SWITCH (
    MAX ( Time_Grain_Parameter[Time_Grain_Parameter] ),
    "Monthly", [Sales Growth % Monthly],
    "Quarterly", [Sales Growth % Quarterly],
    "Yearly", [Sales Growth % Yearly]
)

 

Alternatively, you can create a field parameter using the three measures above but users would need to select both the Time Grain (determines the X-axis column) and the corresponding measure. If your model has more measures than just the sum of sales, consider using a calculation group to avoid creating monthly/quarterly/yearly measures for each base measure.

 

Use these fields in the column chart:

 

DataInsights_0-1739037868423.png

 

DataInsights_1-1739037884617.png

 

DataInsights_2-1739037899186.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hello! I did as you suggested: I created the field parameter, and then all the measures, but when i put the Switch Measure in my report, it shows blank. It does not show any data. What did I do wrong?

Here is the link for the updated file.
https://drive.google.com/file/d/15O-0tr_CwYRBhrdJ1TN6G7sANpw-sAAB/view?usp=sharing 


@EugenioProlog,

 

The switch measure needs to match the names in the field parameter. For example, instead of dsc_mesano, I renamed the field (in the field parameter) to Monthly.

 

Parâmetro-TimeGrain = {
    ("Monthly", NAMEOF('dim__calendario'[dsc_mesano]), 0),
    ("Quarterly", NAMEOF('dim__calendario'[dsc_trimestre]), 1),
    ("Yearly", NAMEOF('dim__calendario'[num_ano]), 2)
}

 

The switch measure uses Monthly:

 

Switch Measure = 
SWITCH (
    MAX ( 'Parâmetro-TimeGrain'[Parâmetro-TimeGrain] ),
    "Monthly", [Sales Growth % Monthly],
    "Quarterly", [Sales Growth % Quarterly],
    "Yearly", [Sales Growth % Yearly]
)

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors