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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
krishna_1811
Frequent Visitor

dax

how to show only quarters when QoQis  selected, months when MoM are selected and years when YOY are selected from the  slicer in a matrix

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @krishna_1811 ,

 

To achieve this in Power BI, you can use a combination of DAX measures and a disconnected table for the slicer. Here's a step-by-step solution with sample data and the expected result:

1.Create a new, disconnected table for the slicer with the options "QoQ", "MoM", and "YoY". You can also create this table by entering data.

SlicerTable = DATATABLE(
    "Period", STRING,
    {
        {"QoQ"},
        {"MoM"},
        {"YoY"}
    }
)

vstephenmsft_0-1737946254280.png

2.Create a measure to calculate the values based on the selected period.

SaSalesAmountlesQoQ = 
VAR SelectedPeriod = SELECTEDVALUE(SlicerTable[Period], "QoQ")
VAR SalesQoQ =
IF(
    SelectedPeriod = "QoQ",
    CALCULATE(SUM(Sales[Amount]), DATESQTD(Sales[Date])),
    BLANK()
)

VAR SalesMoM = 
IF(
    SelectedPeriod = "MoM",
    CALCULATE(SUM(Sales[Amount]), DATESMTD(Sales[Date])),
    BLANK()
)

VAR  SalesYoY = 
IF(
    SelectedPeriod = "YoY",
    CALCULATE(SUM(Sales[Amount]), DATESYTD(Sales[Date])),
    BLANK()
)
RETURN

SalesQoQ + SalesMoM + SalesYoY

 

3.Create a Matrix Visual:

Add a matrix visual to your report.
Use the date field in the rows and the SalesAmount measure in the values.
Add the Period field from the SlicerTable to the slicer visual.

 

Sample Data
Let's assume you have a Sales table with the following data:

Date Amount
2024-01-01 100
2024-02-01 150
2024-03-01 200
2024-04-01 250
2024-05-01 300
2024-06-01 350
2024-07-01 400
2024-08-01 450
2024-09-01 500
2024-10-01 550
2024-11-01 600
2024-12-01 650

 

Expected Result

When you select "QoQ" from the slicer, the matrix should display quarterly sales. When you select "MoM", it should display monthly sales, and when you select "YoY", it should display yearly sales.

vstephenmsft_1-1737946653830.pngvstephenmsft_2-1737946661111.pngvstephenmsft_3-1737946667470.png

 

 

Best Regards,
Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @krishna_1811 ,

 

To achieve this in Power BI, you can use a combination of DAX measures and a disconnected table for the slicer. Here's a step-by-step solution with sample data and the expected result:

1.Create a new, disconnected table for the slicer with the options "QoQ", "MoM", and "YoY". You can also create this table by entering data.

SlicerTable = DATATABLE(
    "Period", STRING,
    {
        {"QoQ"},
        {"MoM"},
        {"YoY"}
    }
)

vstephenmsft_0-1737946254280.png

2.Create a measure to calculate the values based on the selected period.

SaSalesAmountlesQoQ = 
VAR SelectedPeriod = SELECTEDVALUE(SlicerTable[Period], "QoQ")
VAR SalesQoQ =
IF(
    SelectedPeriod = "QoQ",
    CALCULATE(SUM(Sales[Amount]), DATESQTD(Sales[Date])),
    BLANK()
)

VAR SalesMoM = 
IF(
    SelectedPeriod = "MoM",
    CALCULATE(SUM(Sales[Amount]), DATESMTD(Sales[Date])),
    BLANK()
)

VAR  SalesYoY = 
IF(
    SelectedPeriod = "YoY",
    CALCULATE(SUM(Sales[Amount]), DATESYTD(Sales[Date])),
    BLANK()
)
RETURN

SalesQoQ + SalesMoM + SalesYoY

 

3.Create a Matrix Visual:

Add a matrix visual to your report.
Use the date field in the rows and the SalesAmount measure in the values.
Add the Period field from the SlicerTable to the slicer visual.

 

Sample Data
Let's assume you have a Sales table with the following data:

Date Amount
2024-01-01 100
2024-02-01 150
2024-03-01 200
2024-04-01 250
2024-05-01 300
2024-06-01 350
2024-07-01 400
2024-08-01 450
2024-09-01 500
2024-10-01 550
2024-11-01 600
2024-12-01 650

 

Expected Result

When you select "QoQ" from the slicer, the matrix should display quarterly sales. When you select "MoM", it should display monthly sales, and when you select "YoY", it should display yearly sales.

vstephenmsft_1-1737946653830.pngvstephenmsft_2-1737946661111.pngvstephenmsft_3-1737946667470.png

 

 

Best Regards,
Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

rajendraongole1
Super User
Super User

Hi @krishna_1811  - if you can share some sample data, that helps along with your expected output.

 

FOund sme resource Please find the same.

 

Dynamic Columns Based on Slicer Selection in Power BI

Dynamic hierarchy based on filter selection in #Matrix visual #powerbi

 

Please check.





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

Proud to be a Super User!





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.