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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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