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
raj111983
Frequent Visitor

Help with Intersect Function

HI, I just new to Power BI and having difficult time in using Intersect function. Basically I have a single Sales table with multi year data. I created an unrelated Dates table from the Sales  table to use for Slicers. I was able to create a measure for line chart but the chart is not displaying full year for last year. 

The expression I have is below. I am trying to find the Source ID that is in both years for the corresponding month and calculate the sum of Sales.

 

rchitta_0-1730492035541.png

 

What I am seeing is below

rchitta_1-1730492218413.png

 

What I want to see is somthing like below. Full year data for last year and only the data thats available fo rcurrent year. I know its not data related issue as I already checked it. Is Intersect correct method to use in this case? I also tried to create multi line chart with two measures for last year and current year without any luck.

 

rchitta_2-1730492314930.png

 

Your help is appriciated

 

 

1 ACCEPTED SOLUTION

Hi @raj111983 ,

I updated your sample pbix file(see the attachment), please check if that is what you want.

Chart PTran = 
VAR _selyear =
    SELECTEDVALUE ( 'Dates'[Date].[Year] )
VAR _prevyear =
    SELECTEDVALUE ( 'Dates'[Date].[Year] ) - 1
VAR _month =
    SELECTEDVALUE ( 'Sales'[Date].[Month] )
VAR _CSource =
    CALCULATETABLE (
        VALUES ( 'Sales'[Source ID] ),
        FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _selyear )
    )
VAR _PSource =
    CALCULATETABLE (
        VALUES ( 'Sales'[Source ID] ),
        FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _prevyear )
    )
VAR _tab =
    INTERSECT ( _CSource, _PSource )
RETURN
    CALCULATE (
        SUM ( Sales[Measure Value] ),
        FILTER (
            'Sales',
            'Sales'[Date].[Year] = _prevyear
                && 'Sales'[Date].[Month] = _month
                && 'Sales'[Measure Name] = "Volume"
                && 'Sales'[Source ID] IN _tab
        )
    )

vyiruanmsft_0-1730788081746.png

Best Regards

Community Support Team _ Rena
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

7 REPLIES 7
v-yiruan-msft
Community Support
Community Support

Hi @raj111983 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Sel year values = 
VAR _selyear =
    SELECTEDVALUE ( 'Dates'[Year] )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Measure Value] ),
        FILTER (
            ALLSELECTED ( 'Sales' ),
            'Sales'[Measure Name] = "Volume"
                && 'Sales'[Year] = _selyear
                && FORMAT ( 'Sales'[Date], "mmmm" ) = SELECTEDVALUE ( 'Sales'[Date].[Month] )
        )
    )
Pre year values = 
VAR _selyear =
    SELECTEDVALUE ( 'Dates'[Year] )
RETURN
    CALCULATE (
        SUM ( 'Sales'[Measure Value] ),
        FILTER (
            ALLSELECTED ( 'Sales' ),
            'Sales'[Measure Name] = "Volume"
                && 'Sales'[Year] = _selyear - 1
                && FORMAT ( 'Sales'[Date], "mmmm" ) = SELECTEDVALUE ( 'Sales'[Date].[Month] )
        )
    )

vyiruanmsft_0-1730688589376.png

Best Regards

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

Hi,

 

THank you very much for the reply. But that is not what I was looking for. I posted a sample file and more explanation of what I was looking for. I am trying calculate current year and previous for onlt the Source ID's that are reporting data for corrsponding months in each year. Lets say, if Source ID "A" is only reporting data for January and March for one of the years then that Source ID should only be included for Jan and March for both current and previous years.

PhilipTreacy
Super User
Super User

@raj111983 

 

Please supply your data, it makes it so much easier to debug than just some images.

 

Thanks

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi,

Sample data is in Drop Box folder. Please le tme know if you can access it.

https://www.dropbox.com/scl/fi/q9lssc3mam3dji5ohohq6/Sample.xlsx?rlkey=p3ylb5r35d0ar0be66zsu4zmg&st=...

As you can see the data, Source ID AHA is present in 2024 so that shouldnt be included in the chart for current or previous year. Same with Source ID FKA, data is not availabel for Jan2023 so it shouldnt be included in Jan2024 sum. This is to Apples-Apples comparisionby Source ID and Month. I want to show full year last year and current year. But when I use intersect function, its only showing the data till Septemper.

Thank you!!

Hi,

 

Here is the pbix with sample data. I wanted the previous year 

https://www.dropbox.com/scl/fi/ikzyz7f7r8ofzlfqikmua/Sample.pbix?rlkey=y7hd05n7gn8lilow5ylfnguak&st=...

 

Hi @raj111983 ,

I updated your sample pbix file(see the attachment), please check if that is what you want.

Chart PTran = 
VAR _selyear =
    SELECTEDVALUE ( 'Dates'[Date].[Year] )
VAR _prevyear =
    SELECTEDVALUE ( 'Dates'[Date].[Year] ) - 1
VAR _month =
    SELECTEDVALUE ( 'Sales'[Date].[Month] )
VAR _CSource =
    CALCULATETABLE (
        VALUES ( 'Sales'[Source ID] ),
        FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _selyear )
    )
VAR _PSource =
    CALCULATETABLE (
        VALUES ( 'Sales'[Source ID] ),
        FILTER ( ALLSELECTED ( 'Sales' ), 'Sales'[Date].[Year] = _prevyear )
    )
VAR _tab =
    INTERSECT ( _CSource, _PSource )
RETURN
    CALCULATE (
        SUM ( Sales[Measure Value] ),
        FILTER (
            'Sales',
            'Sales'[Date].[Year] = _prevyear
                && 'Sales'[Date].[Month] = _month
                && 'Sales'[Measure Name] = "Volume"
                && 'Sales'[Source ID] IN _tab
        )
    )

vyiruanmsft_0-1730788081746.png

Best Regards

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

Thank you!! Worked Perfectly!!

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.