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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
razieh1990
Helper I
Helper I

data filter

Hello 

I appreciate it if you help me.

I have a dataset including all the sales from 2018. and I imported data not direct query.

I want to create a matrix in Power BI similar to the below layout. 

On the page there is a year selection, each year I choose in the slicer, the data for that year should be displayed by month, and also the target should display the target of the selected year and for the rest of the years, the data should be aggregated and displayed yearly.

and the columns should be sorted ascending. for example, if I choose 2022: the layout should be like the matrix below.

for 2024:

image.jpeg

for 2022:

 

 

photo_2024-03-08 14.39.51.jpeg

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

Hi @razieh1990 

You can refer to the following sample.

Sample data 

vxinruzhumsft_5-1710227175050.png

1.Create a type table

vxinruzhumsft_4-1710227152179.png

 

2.Create a year table

vxinruzhumsft_2-1710226927151.png

There is no relationship among the tables.

3.Create a measure

 

MEASURE =
IF (
    ISFILTERED ( 'Year'[Year] ),
    IF (
        SELECTEDVALUE ( 'Type'[Type] ) = "Target",
        CALCULATE (
            SUM ( 'Table'[Target] ),
            YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'Year'[Year] )
        ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            OR (
                FORMAT ( YEAR ( 'Table'[Date] ), "" )
                    IN VALUES ( 'Type'[Type] )
                        && YEAR ( 'Table'[Date] ) <> SELECTEDVALUE ( 'Year'[Year] ),
                YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'Year'[Year] )
                    && FORMAT ( 'Table'[Date], "mmmm" ) = SELECTEDVALUE ( 'Type'[Type] )
            )
        )
    ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FORMAT ( YEAR ( 'Table'[Date] ), "" ) IN VALUES ( 'Type'[Type] )
    )
)

 

4.Put the year field to the slicer, and put the type field and measure to the matrix visual.

Output

vxinruzhumsft_6-1710227490192.png

 

Best Regards!

Yolo Zhu

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

3 REPLIES 3
v-xinruzhu-msft
Community Support
Community Support

Hi @razieh1990 

You can refer to the following sample.

Sample data 

vxinruzhumsft_5-1710227175050.png

1.Create a type table

vxinruzhumsft_4-1710227152179.png

 

2.Create a year table

vxinruzhumsft_2-1710226927151.png

There is no relationship among the tables.

3.Create a measure

 

MEASURE =
IF (
    ISFILTERED ( 'Year'[Year] ),
    IF (
        SELECTEDVALUE ( 'Type'[Type] ) = "Target",
        CALCULATE (
            SUM ( 'Table'[Target] ),
            YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'Year'[Year] )
        ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            OR (
                FORMAT ( YEAR ( 'Table'[Date] ), "" )
                    IN VALUES ( 'Type'[Type] )
                        && YEAR ( 'Table'[Date] ) <> SELECTEDVALUE ( 'Year'[Year] ),
                YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'Year'[Year] )
                    && FORMAT ( 'Table'[Date], "mmmm" ) = SELECTEDVALUE ( 'Type'[Type] )
            )
        )
    ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FORMAT ( YEAR ( 'Table'[Date] ), "" ) IN VALUES ( 'Type'[Type] )
    )
)

 

4.Put the year field to the slicer, and put the type field and measure to the matrix visual.

Output

vxinruzhumsft_6-1710227490192.png

 

Best Regards!

Yolo Zhu

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

 

Thank you very much

lucadelicio
Super User
Super User

Hi,

try to upload on https://wetransfer.com/
the file pbix with the data and upload an image that is visible with the result that you want.
Not a photo of your pc but a screen you can use the windows tool (Win + Caps + S)
Thank you.

Luca D'Elicio

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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