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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
SDK0415
Frequent Visitor

Dynamic columns in Matrix table based on two slicers

I have a sales table that has 4 fields Region, Prod category, Calendar Month and Net Sales.

Source.png

I would like to see one matrix table in Power BI in such a way that I compare two months of data based on two date slicers namely date slicer 1 and date slicer 2. Also I want to calculate the deviation between the months.

If in Date slicer 1 Jan and in Date slicer 2 Feb is selected then the output should be like below

Result 1.png

If in Date slicer 1 Jan and in Date slicer 2 Mar is selected then the output should be like below

Result 2.png

How is this possible in Power BI.?

1 ACCEPTED SOLUTION
v-yaningy-msft
Community Support
Community Support

Hi, @SDK0415 

Thanks for @Uzi2019 and @Kishore_KVN reply. The current version of the matrix does not support the use of Measure as a column, you can try the following method to create multiple Measure to be placed in the Card.

vyaningymsft_1-1720157763136.pngvyaningymsft_2-1720157775130.png

Measure:

Diviation Electronics = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
VAR _minMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
RETURN
    _maxMonthElectronicsNetSales - _minMonthElectronicsNetSales

Diviation Furniture = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
VAR _minMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
RETURN
    _maxMonthFurnitureNetSales - _minMonthFurnitureNetSales

Diviation% Electronics = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
VAR _minMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
RETURN
    DIVIDE (
        _maxMonthElectronicsNetSales - _minMonthElectronicsNetSales,
        _minMonthElectronicsNetSales
    )

Diviation% Furniture = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
VAR _minMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
RETURN
    DIVIDE (
        _maxMonthFurnitureNetSales - _minMonthFurnitureNetSales,
        _minMonthFurnitureNetSales
    )

 

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
v-yaningy-msft
Community Support
Community Support

Hi, @SDK0415 

Thanks for @Uzi2019 and @Kishore_KVN reply. The current version of the matrix does not support the use of Measure as a column, you can try the following method to create multiple Measure to be placed in the Card.

vyaningymsft_1-1720157763136.pngvyaningymsft_2-1720157775130.png

Measure:

Diviation Electronics = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
VAR _minMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
RETURN
    _maxMonthElectronicsNetSales - _minMonthElectronicsNetSales

Diviation Furniture = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
VAR _minMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
RETURN
    _maxMonthFurnitureNetSales - _minMonthFurnitureNetSales

Diviation% Electronics = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
VAR _minMonthElectronicsNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Electronics"
    )
RETURN
    DIVIDE (
        _maxMonthElectronicsNetSales - _minMonthElectronicsNetSales,
        _minMonthElectronicsNetSales
    )

Diviation% Furniture = 
VAR _maxCalendarMonth =
    CALCULATE ( MAX ( 'Table'[Month Number] ) )
VAR _minCalendarMonth =
    CALCULATE ( MIN ( 'Table'[Month Number] ) )
VAR _maxMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _maxCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
VAR _minMonthFurnitureNetSales =
    CALCULATE (
        SUM ( 'Table'[Net Sales] ),
        'Table'[Month Number] = _minCalendarMonth
            && 'Table'[Prod Category] = "Furniture"
    )
RETURN
    DIVIDE (
        _maxMonthFurnitureNetSales - _minMonthFurnitureNetSales,
        _minMonthFurnitureNetSales
    )

 

Best Regards,
Yang

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Uzi2019
Super User
Super User

Hi @SDK0415 

 

Try below video these videos will help you.
https://www.youtube.com/watch?v=_QmF0q2JfvQ

 

https://www.youtube.com/watch?v=vzI9T3Wdpak
https://www.youtube.com/watch?v=knXFVf2ipro&t=914s

https://www.youtube.com/watch?v=TF0lPIYjJfs&t=1s

https://www.youtube.com/watch?v=DGRCLcfUHM4&t=608s

 

https://www.youtube.com/watch?v=O0VsTLDTjss&t=332s

 

 

I hope I answered your question!

Combination of all above video would give you desired result.

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Kishore_KVN
Super User
Super User

Hello @SDK0415 ,

You have to use SELECTEDVALUE DAX function to select the period and implement it in the Deviation calculation. 

For example:

Deviation = 
VAR A = SELECTEDVALUE(DATESLICER1)
VAR B = SELECTEDVALUE(DATESLICER2)
RETURN
B-A

This is just example. Depends on your data change accordingly. 

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.